Nullability
NULL (class)
null (singleton object)
int // cannot contain null
int? // includes null
// note nullable types still contain the same methods as their non nullable
// brothers. But you may need to check to ensure that the variable is not null
dynamic // includes null even without a ?
All ? types are init as null
Null operators
??: If-null operator.text = message ?? 'Error';
if left is null use right
??=: Null-aware assignment operator.fontSize ??= 20.0;if left is null, left = right
?.: Null-aware access operator. && Null-aware method invocation operator.print(age?.isNegative);
if age is null, return null
Note: isNeg will not work if null normally
!: Null assertion operator.String nonNullableString = myNullableString!;
Allows you to turn a nullable value into non nullable
Note: wont work if it is null
?..: Null-aware cascade operator.
user
?..name = 'Ray'
..id = 42;
// if user is null then abort
?[]: Null-aware index operator.
...?: Null-aware spread operator.
Null operators
??: If-null operator.
??=: Null-aware assignment operator.
?.: Null-aware access operator.
?.: Null-aware method invocation operator.
!: Null assertion operator.
?..: Null-aware cascade operator.
?[]: Null-aware index operator.
...?: Null-aware spread operator.