A ? after a type marks the value as nullable. Without ?, the variable can never be null.

Program

Play the program to assign and print a nullable name.

nullable.dart
Replay: real traced execution (multi-file project)
void main() {
  String? name;
  print(name);
  name = 'Ada';
  print(name);
}
  1. name ← null

    1void main() {2  String? name;3  print(name);
    values this stepnullname
  2. print(name);

    2String? name;3print(name);4name = 'Ada';
    outputnull
    values this stepnullname
  3. name ← Ada

    3print(name);4name = 'Ada';5print(name);
    values this stepnull Adaname
  4. print(name);

    4  name = 'Ada';5  print(name);6}
    outputAda
    values this stepAdaname
String? `?` makes the variable's type nullable.
default null An uninitialized nullable starts as `null`.
non-nullable Without `?`, the compiler rejects `null` assignments.