String foo = 'a string'; String bar; // Unassigned objects are null by default.
// Substitute an operator that makes 'a string' be assigned to baz. String baz = foo ?? bar;
void updateSomeVars() { // Substitute an operator that makes 'a string' be assigned to bar. bar ??= 'a string'; }
Conditional property access
myObject?.someProperty equals to (myObject != null) ? myObject.someProperty : null.
1 2 3 4 5 6
// This method should return the uppercase version of `str` // or null if `str` is null. String upperCaseIt(String str) { // Try conditionally accessing the `toUpperCase` method here. return str?.toUpperCase(); }
Cascades
myObject.someMethod() will get the return value of the someMethod(), myObject..someMethod() will get the reference of the myObject.
// Create a named constructor called "black" here and redirect it // to call the existing constructor Color.assign(int red, int green, int blue): this(red, green, blue); Color.black(): this.assign(0, 0, 0); }