Reputation: 13860
This is the new assignment operator I see in Flutter source code:
splashFactory ??= InkSplash.splashFactory;
textSelectionColor ??= isDark ? accentColor : primarySwatch[200];
what's the meaning of this assignment operator?
example in Flutter source code
Upvotes: 6
Views: 1781
Reputation: 1000
?? is a null check operator.
String name=person.name ?? 'John';
if person.name is null, then name is assigned a value of “John”.
??= simply means “If left-hand side is null, carry out assignment”. This will only assign a value if the variable is null.
splashFactory ??= InkSplash.splashFactory;
Upvotes: 2
Reputation: 6029
??= is a new null-aware operators. Specifically ??= is null-aware assignment operator.
?? if null operator.
expr1 ?? expr2
evaluates toexpr1
if notnull
, otherwiseexpr2
.
??= null-aware assignment.
v ??= expr
causesv
to be assignedexpr
only ifv
isnull
.
?. null-aware access.
x?.p
evaluates tox.p
ifx
is notnull
, otherwise evaluates tonull
.
Upvotes: 8
Reputation: 109
The ?? double question mark operator means "if null" take the following expression.
Upvotes: 0