Top 10 Function that puzzle developers new to Flutter (Darts)
Dollar sign ($) - $string1/{exp1}
Cascade Notation (..)
Been seeing methods with double dots preceding e.g. ..add()/..remove() lurking around and can't figure out whether it is deliberate or typo. Fret not, its not a typo.
Cascade notation allows you to combine multiple method of the same class in an expression without repeating the classname/prefix. i.e. chain methods
Example below:
myTable.add("Name");
myTable.add("Address");
Putting a dollar syntax/sign in front of a variable or expression would tell compiler to look at value of var/exp. In essence, String Interpolation.
e.g.
Input:
String food1 = "Burger"
String food2 = "sushi"
print('My favourite food1 is $food and ${food2.upper()}');
Output:
Burger
SUSHI
Cascade Notation (..)
Been seeing methods with double dots preceding e.g. ..add()/..remove() lurking around and can't figure out whether it is deliberate or typo. Fret not, its not a typo.
Cascade notation allows you to combine multiple method of the same class in an expression without repeating the classname/prefix. i.e. chain methods
Example below:
myTable.add("Name");
myTable.add("Address");
myTable.add("Mobile");
myTable.remove("Fax");
myTable.remove("Fax");
Cascade Notation:
myTable..add("Name")..add("Address")..add("Mobile")..remove("Fax")
Async*
Same goes for Sync* which returns an iterable object.
?. Operator e.g. Obj1?.method1
This operator goes by many names; Unary Post-fix or Conditional member access.
Regardless, it does only one thing, check if object i.e. left operand is not null, execute method1.
Async*
Ever thought why Async comes with a * operator/syntax.
This is to implement an asynchronous generator function which lazily produce a sequences of value. A stream object would be return.
e.g.
Stream<int> test(int i) async* {
int count = 0;
while (count < i) yield count++;
}
?. Operator e.g. Obj1?.method1
This operator goes by many names; Unary Post-fix or Conditional member access.
Regardless, it does only one thing, check if object i.e. left operand is not null, execute method1.
Comments
Post a Comment