Flutter ● ● ○ Dart 3.6

Kodebits Day 12: Null-aware Operators

Apr 26 2026
Combine safe access and fallback defaults in Dart.

What does this print?

String tag(String? s) {
  final v = s ?? 'none';
  return v.toUpperCase();
}
void main() {
  print(tag('dart'));
  print(' / ');
  print(tag(null));
}


Try it in the online Dart Playground →

[spoiler title="Solution"]

Answer:

DART / NONE

Explanation:

The ?? operator provides ‘none’ as a default when s is null. v is thus a String which can be upcased.

[/spoiler]


Further Reading