- In dart unassigned variables are by default assigned null at initialization.
- In Null safety a variable with a static type should be assigned some value at initialization
or if that variable is to be assigned a value later then should be declare with
late
or made null aware by using ? operator after its type. - Statically typed variables declared without null aware (?) operator can never be null in Null safety
@required
is changed torequired
in Null Safety- We have various operators and annotations in Null Safety such as
?. ?? ??= !. late required
?? this is Null-ish Coalescing operator which assigns a LHS value only if it's not null otherwise it assigns RHS value
- Eg.
a = b ?? c
?. this is null aware access operator which basically tells that value being accessed can be null
- Eg. someString?.toLowerCas() // will output null if someString is null otherwise gives the result
! Bang operator is to be used if you are sure that the value being accessed is not null
- Eg. object!["property"]