Dart  Control  FLow  Operators

Dart Control FLow Operators

Control flow operator

  • Dart offers collection if and collection for for use in list, map, and set literals.

  • You can use these operators to build collections using conditionals (if) and repetition (for).

Example

var nav = ['Home', 'Furniture', 'Plants', if (promoActive) 'Outlet'];
  • If - case statement
var nav = ['Home', 'Furniture', 'Plants', if (login case 'Manager') 'Inventory'];
  • collection for to manipulate the items of a list before adding them to another list.
var listOfInts = [1, 2, 3];
var listOfStrings = ['#0', for (var i in listOfInts) '#$i'];
assert(listOfStrings[1] == '#1');