Answers for "dart if object==null"

0

dart if object==null

In other languages we can use the logical-or shortcut. If maybeSomeNumber() 
returns null, assign a default value of 2:

value = maybeSomeNumber() || 2

In Dart we can’t do this because the expression needs to be a boolean (“the 
operands of the || operator must be assignable to bool").
That’s why the ?? operator exists:

var value = maybeSomeNumber() ?? 2;
Posted by: Guest on January-13-2022

Code answers related to "Dart"

Browse Popular Code Answers by Language