DART 3 (alpha release)
DART 3 is a new major release - only supports sound null safety.
DART 3 comes with two new MAJOR FEATURES - "RECORDS AND PATTERNS" , with the goal to work with structured data more productively.
Records :
“ Allows us to combine multiple datatypes to a single type”
Patterns :
“ Allows us to de-couple coupled data into its constituents”
Multiple Returns
Records are sort of like "first-class argument lists" and give you a natural way to return multiple values
- If you don't want to access everything returned from the function, in that case, you can keep “_” at that place.
Example:
O/P:
DeStructuring:
Record patterns in variable declarations let you destructure a record value by accessing fields and binding the resulting values to new variables
List and map patterns let you likewise destructure those respective collection types
Example:
O/P:
Destructuring and assigning values to existing variables
Example:
o/p:
Json DeStructuring:
- Can easily destructure json which is easy to use
Example:
o/p:
Example:
o/p:
Usable Switches:
Added guarded clauses, let you evaluate an arbitrary expression to see if that case should match
Also allows logical and comparison operators
Earlier:
After Dart 3.0:
- Now, can add multiple small patterns into a single case
- Also can add switch expressions
Control Flow in Arguments list
Earlier:
After Dart 3:
Subscribe to my newsletter
Read articles from Srushti Patel directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by