Records & Patterns — Dart | Flutter 💙

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

Abhishek Doshi
Google Developer Experts
2 min readFeb 22, 2023

--

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:

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

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

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

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

--

--

Abhishek Doshi
Abhishek Doshi

Written by Abhishek Doshi

Google Developer Expert — Dart, Flutter & Firebase 💙💛

Responses (1)