You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int x; // The initial value of any object is null// ?? null aware operator
x ??=6; // ??= assignment operator, which assigns a value of a variable only if that variable is currently nullprint(x); //Print: 6
x ??=3;
print(x); // Print: 6 - result is still 6print(null??10); // Prints: 10. Display the value on the left if it's not null else return the value on the right
// to insert multiple values into a collection.var list = [1, 2, 3];
var list2 = [0, ...list];
print(list2.length); //Print: 4
Cascade notation (..)
// allows you to make a sequence of operations on the same object// rather than doing thisvar user =User();
user.name ="Nicola";
user.email ="[email protected]";
user.age =24;
// you can do thisvar user =User()
..name ="Nicola"
..email ="[email protected]"
..age =24;
Conditional Property Access
userObject?.userName
//The code snippet above is equivalent to following:
(userObject !=null) ? userObject.userName :null//You can chain multiple uses of ?. together in a single expression
userObject?.userName?.toString()
// The preceeding code returns null and never calls toString() if either userObject or userObject.userName is null