A lot of Dart code in 2026 is still written like it is 2022: a throwaway class to return two values, a null-check ladder to read JSON, if (x != null) map['x'] = x; three times in a row, MainAxisAlignment.center spelled out in every Row.
Dart has quietly fixed most of that. The language added something useful in almost every release since 3.0, and each one is small enough to miss in a changelog. This post collects the twelve that change everyday code the most, with the version that introduced each one.
Every example below was compiled and run on Dart 3.13.7 (Flutter 3.47.9 stable) with sdk: ^3.13.0 in pubspec.yaml. If your constraint is lower, a feature is only available once your package’s lower bound reaches the version shown.
Quick reference
| Trick | Dart version | Replaces |
|---|---|---|
| Records | 3.0 | Small classes made only to return two values |
| Sealed classes and switch expressions | 3.0 | if/else chains over state, missing-case bugs |
if-case patterns |
3.0 | Nested is checks when reading JSON |
| Extension types | 3.3 | Mixing up IDs that are all String |
| Digit separators | 3.6 | Counting zeros in 25000000 |
Wildcard _ |
3.7 | _, __, ___ for unused parameters |
| Null-aware elements | 3.8 | if (x != null) inside collection literals |
| Dot shorthands | 3.10 | Repeating the type name the compiler already knows |
| Private named parameters | 3.12 | Writing a constructor by hand for private fields |
| Primary constructors | 3.13 | Field + constructor boilerplate in small classes |
new(...) constructors |
3.13 | Repeating the class name in every constructor |
| New core APIs | 3.13 | Small helpers you used to write yourself |
1. Return two values with a record (Dart 3.0)
Before records, a function that needed to return a count and an average either returned a Map (no types) or a class used in exactly one place. A record is a typed, anonymous tuple, and you can destructure it where you call the function:
(int count, double average) stats(List<int> scores) {
final total = scores.fold(0, (sum, s) => sum + s);
return (scores.length, scores.isEmpty ? 0 : total / scores.length);
}
final (count, average) = stats([90, 75, 100]);
print('$count scores, average $average'); // 3 scores, average 88.33…
Records have value equality and a correct hashCode for free, so they also work as map keys, for example Map<(int, int), Tile> for a grid.
When not to use one: if the same shape travels through several layers of your app, give it a name with a class. A record is best for values that are created and taken apart close together.
2. Make state exhaustive with sealed classes and switch expressions (Dart 3.0)
This is the trick with the biggest payoff in Flutter apps. Mark a state hierarchy sealed, and the compiler knows every subtype. A switch expression over it must then handle every case, so adding a new state later turns every forgotten screen into a compile error instead of a runtime surprise.
sealed class LoadState {}
class Loading extends LoadState {}
class Loaded extends LoadState {
Loaded(this.items);
final List<String> items;
}
class Failed extends LoadState {
Failed(this.message);
final String message;
}
String label(LoadState state) => switch (state) {
Loading() => 'Loading…',
Loaded(items: []) => 'Nothing here yet',
Loaded(:final items) => '${items.length} items',
Failed(:final message) => 'Error: $message',
};
Two details are doing a lot of work. Loaded(items: []) matches only an empty list, so the empty state gets its own case without an if. :final items is shorthand for items: final items: it pulls the field out under the same name.
In a widget, the same pattern returns widgets instead of strings. We go deeper on designing those states in loading, empty and error states.
3. Validate JSON in one line with if-case (Dart 3.0)
Reading nested JSON safely used to mean checking every level with is and casting. A map pattern does the checks and the binding together, and simply does not match if any key is missing or has the wrong type:
String? cityOf(Map<String, Object?> json) {
if (json case {'address': {'city': String city}}) return city;
return null;
}
cityOf({'address': {'city': 'Lahore'}}); // Lahore
cityOf({'address': {'city': 42}}); // null, no exception
It is not a replacement for a proper model class when you parse a whole API response. It is ideal for the small, one-off reads: a push notification payload, a deep-link parameter, a feature flag.
4. Stop mixing up IDs with extension types (Dart 3.3)
When userId, orderId and productId are all String, nothing stops you passing one where another belongs. An extension type gives a value its own static type with no runtime cost: at runtime it is still just the String.
extension type const UserId(String value) {
bool get isGuest => value.startsWith('guest_');
}
void loadProfile(UserId id) => print('loading ${id.value}');
const id = UserId('guest_42');
loadProfile(id); // fine
// loadProfile('42'); // compile error: a String is not a UserId
print(id.isGuest); // true
Because there is no wrapper object, extension types are safe to use in hot paths and large lists. The trade-off: since the type disappears at runtime, is UserId checks and List<UserId> casts cannot tell it apart from a String. Use it for compile-time safety, not for runtime type checks.
5. Make big numbers readable with digit separators (Dart 3.6)
const maxUploadBytes = 25_000_000;
const oneSecondMicros = 1_000_000;
Underscores in number literals are ignored by the compiler. That one change makes size limits, timeouts and money in minor units much harder to get wrong by a zero.
6. Ignore what you do not need with wildcard _ (Dart 3.7)
Since Dart 3.7, a local variable or parameter named _ does not bind anything, so you can use it as many times as you want:
void onTap(Object _, Object _) => print('tapped');
final pairs = [(1, 'a'), (2, 'b')];
for (final (_, letter) in pairs) {
print(letter);
}
In Flutter you will mostly use this in callbacks, such as (_, _) => ... in a builder that does not need its BuildContext or index. No more (_, __).
7. Drop if (x != null) from collections with null-aware elements (Dart 3.8)
Building a query map or a request body with optional values used to need an if per entry. A ? in front of a key’s value (or a list element) inserts it only when it is not null:
Map<String, Object> query({String? search, int? page}) => {
'limit': 20,
'search': ?search,
'page': ?page,
};
query(search: 'flutter'); // {limit: 20, search: flutter}
query(page: 2); // {limit: 20, page: 2}
Notice the result type is Map<String, Object>, not Map<String, Object?>. The nulls never get in, and the type says so. It works in lists and sets too: [header, ?subtitle, body].
8. Let the type speak with dot shorthands (Dart 3.10)
When the compiler already knows which type a value must be, you can leave the type name off and start with a dot:
enum Status { idle, running, done }
Status current = .running;
final Duration timeout = .new(seconds: 5);
This works for enum values, static members, constructors (.new) and named constructors. In Flutter code it shortens the most repeated lines in any widget tree:
Column(
mainAxisAlignment: .center,
crossAxisAlignment: .start,
children: [...],
)
Use it where the type is obvious from the parameter name. alignment: .center reads fine. A shorthand passed to a parameter typed Object, or deep inside a generic call, will not compile, and it would not help the reader if it did.
9. Keep fields private without writing the constructor yourself (Dart 3.12)
Until Dart 3.12, you could not use this._balance in a named parameter, because a named parameter cannot be private. So a class with a private field needed a hand-written initializer list. Now the leading underscore is stripped from the public name:
class Account {
Account({required this._balance});
final int _balance;
int get balance => _balance;
}
Account(balance: 10); // callers write `balance`, the field stays private
10. Declare small classes in one line with primary constructors (Dart 3.13)
The headline feature of Dart 3.13. The constructor and its fields move into the class header:
class Point(final int x, final int y);
That one line declares two final fields and a constructor Point(int x, int y). A body is still allowed when you need getters or methods. We covered the rules, the edge cases and how to adopt it safely in Dart 3.13 primary constructors: what Flutter developers need to know.
11. Write new and factory instead of the class name (Dart 3.13)
Less known, and arguably more useful day to day: inside a class body you can now write new instead of repeating the class name, and factory name for a named factory.
class Loaded {
new(this.items);
final List<String> items;
}
class Temperature(final double celsius) {
factory fromFahrenheit(double f) => Temperature((f - 32) * 5 / 9);
}
Temperature.fromFahrenheit(212).celsius; // 100.0
Callers do not change: it is still Loaded([...]) and Temperature.fromFahrenheit(...). Renaming a class no longer means editing every constructor.
Dart 3.13 also ships a lint for this, unnecessary_type_name_in_constructor. When we enabled it on the examples in this post, it flagged every classic constructor and suggested the short form. Along with use_declaring_parameters, it is a good way to let dart fix --apply modernise a codebase gradually instead of in one huge diff:
# analysis_options.yaml
linter:
rules:
- unnecessary_type_name_in_constructor
- use_declaring_parameters
12. Use the small Dart 3.13 core library additions
A few helpers you have probably written yourself are now in the SDK:
final frozen = List<int>.unmodifiableOf([1, 2, 3]);
frozen.add(4); // throws UnsupportedError
Map<String, int>.unmodifiableOf({'a': 1});
12.oneBitCount; // 2 (binary 1100)
8.trailingZeroBitCount; // 3 (binary 1000)
await Future.pause(const Duration(milliseconds: 10));
List.unmodifiableOfandMap.unmodifiableOfare the new names for theunmodifiableconstructors. The source ofList.unmodifiablealready carries a commented-out@Deprecated("Use List.unmodifiableOf instead"), so expect the old names to be deprecated later.oneBitCountandtrailingZeroBitCountare handy for bit flags and permissions. Note that they count 64 bits on native platforms and 32 bits on the web.Future.pausewaits without doing anything and can never complete with an error. It is clearer thanFuture.delayed(duration)when all you want is a delay, for example between retries.
One to avoid: Dart 3.13 also exposed Isolate.runSync and some related isolate APIs. The Dart 3.14 changelog removes them, saying they were exposed by accident. Do not build on them.
How to start using these in an existing project
- Raise the SDK lower bound in
pubspec.yaml. Features are tied to the language version of your package, not the SDK you have installed.sdk: ^3.13.0turns on everything in this post. - Run
dart fix --dry-run, thendart fix --apply, with the lints above enabled. It handles the mechanical changes. - Adopt the rest when you touch a file. Sealed state,
if-caseand extension types are design changes. Introduce them in the code you are already changing, with tests, instead of rewriting a working app in one go. - Watch for Dart 3.14. It is due with Flutter 3.50 this month and adds
dart migrate, which raises SDK constraints one minor version at a time. Our Flutter 3.50 upgrade checklist covers the rest of that release.
If you want more habits like these applied across a whole Flutter app, read Flutter best practices in 2026. And if you would rather have a senior Flutter developer modernise your codebase, Feemag does that work.
Sources
- Dart: Language evolution (features by version, 3.6 to 3.13)
- Dart: SDK changelog, 3.12 (May 18, 2026) and 3.13 (August 12, 2026)
- Dart: SDK changelog on GitHub, 3.14.0 section (unreleased at the time of writing)
- Dart: Patterns, Extension types, Primary constructors
- Dart SDK 3.13.7 source:
List.unmodifiableOf,int.oneBitCount,int.trailingZeroBitCountandFuture.pauseAPI docs