Dart 3 brought records and patterns — features that quietly remove a lot of boilerplate from everyday Flutter code. Here's how to use them.
Records: Return Multiple Values
// No need for a one-off class just to return two things
(int, String) parse(String input) {
return (200, "OK");
}
final (code, message) = parse("...");
print('$code $message'); // 200 OKPattern Matching With switch Expressions
String describe(Object value) => switch (value) {
(int x, int y) => 'Point($x, $y)',
[var first, ...] => 'List starting with $first',
String s when s.isEmpty => 'Empty string',
_ => 'Something else',
};Destructuring in if-case
if (response case {'status': 200, 'data': var data}) {
handleSuccess(data);
}Where It Shines
Parsing JSON, modeling API states (loading/error/data), and returning coordinate/result pairs all become dramatically cleaner with records and patterns.
