Records & Patterns — Dart | Flutter

records-&-patterns — dart-|-flutter

Records & Patterns — Dart | Flutter 💙

Unlock the Full Potential of Your Dart Applications with Powerful Records and Patterns 🥷🏻

From Dart 3ɑ, the Flutter team introduced a new data type called Records & Patterns. Do you know what they are? Not to worry. Let’s check them out in detail with the help of this article 🥳

NOTE: When this article was written, Records & Patterns were available in Flutter Master Channel.

Records allow you to efficiently and concisely create anonymous composite values from any existing data. In other words, you can return multiple values from a function without making a model/temporary class for it!!!

What are Patterns or Pattern Matching? Patterns can destructure composite data into its constituents. Patterns are fully type-safe and checked during development. Well, Patterns allow us to conditionally assign parameters simply using if-else.

Initially, we created a model class to store multiple values, like the following:

https://medium.com/media/2baefc17b9742ad041a5f44624277ea5/href

And then return them from our function. Something like the following:

https://medium.com/media/1cf3ffd637d8bceaad3831d202acb1c1/href

Easy and simple right? But now let’s check out how it will look when we use Records 🤩

https://medium.com/media/2aac4ab2cb6348f1c8196b4f080221db/href

So, using Records & Patterns is quite simple. You can return firstName and lastName together from our function as follows:

https://medium.com/media/54d5f04301b7dde4cf58f77cbccb93c9/href

Records & Patterns make our life simpler. We don’t have to create model classes with 2–3 variables. We can simply use Records & Patterns for this purpose 🥳

Check out the entire example in GitHub Repository 💙

Hope you enjoyed this article!

Doubts? Feel free to drop a message @AbhishekDoshi26

Don’t stop, until you are breathing!💙
– Abhishek Doshi


Records & Patterns — Dart | Flutter 💙 was originally published in Google Developer Experts on Medium, where people are continuing the conversation by highlighting and responding to this story.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
how-does-qa-ensure-regulatory-compliance-for-canadian-digital-banks?

How Does QA Ensure Regulatory Compliance for Canadian Digital Banks?

Next Post
how-to-track-user-sentiment-vs.-user-behavior-in-your-content

How to Track User Sentiment vs. User Behavior in Your Content

Related Posts