The following line of code has two question marks:
final myStringList = prefs.getStringList('my_string_list_key') ?? [];
What is the meaning?
The ?? double question mark operator means "if null". Take the following expression, for example.
??
String a = b ?? 'hello';
This means a equals b, but if b is null then a equals 'hello'.
a
b
'hello'
Another related operator is ??=. For example:
??=
b ??= 'hello';
This means if b is null then set it equal to hello. Otherwise, don't change it.
hello
Reference
Terms
The Dart 1.12 release news collectively referred to the following as null-aware operators:
x?.p
x?.m()
2.1m questions
2.1m answers
60 comments
57.0k users