On Github nitya / flydart
welcome() .then((_) => introduceDart()) // 30 minutes .then((_) => codeLab(part1)) // 1 hour .then((_) => eatPizzas()) // 30 minutes .then((_) => codeLab(part2)) // 1 hour .then((_) => takeSurvey()); // 5 minutes
var name = 'Robert Nelson';
var m = 3; num n = 9; int x = 33; double y = 2.548;
bool selected = false; var displayed = true;
List names = ['Anne', 'Robert', 'Louise']; var towns = []; List countries = new List(); countries.add('France'); String name = name.length > 1 ? name[1] : "unknown";
Map names = { 'Dart' : 'http://www.dartlang.org', 'Html5Rock' : 'http://www.html5rocks.com' }; Map dartFS = new Map(); dartFS['Montpellier'] = 'http://www.jug-montpellier.org'; dartFS['Paris'] = 'http://www.parisjug.org'; String url = dartFS['Montpellier'];
class Hug { int strength; // Public attribute // --- Modify online to use a getter --- Hug(this.strength); // Terse Hug operator +(Hug other) { // Operator overriding return new Hug(strength + other.strength); } } Hug hug = new Hug(10); int v = hug.strength;
class Hug { ... // Optional params w/ default value void patBack({int hands: 1}) { ... } // Named params w/ default value void sayGoodBye([int times= 1]) { ... } // One line function & String interpolation String toString() => "Embraceometer reads $_strength"; }
class Hug { static Hug _shared = new Hug(99); // Default constructor (no name) Hug(this._strength); // Named constructor Hug.withFriend(int strength) : this(strength * 2); // Factory : new Hug.shared() return the same instance factory Hug.shared() => _shared; }
class Employee extends Persistable { ... }
class Employee extends Person with Persistable { ... }
List dfSchools = new List(); dfSchools.add('San Francisco'); dfSchools.add('Montpellier'); dfSchools.add('Paris');
List dfSchools = new List() ..add('San Francisco') ..add('Montpellier') ..add('Paris');
String addSign(String msg) { return '$msg (from Montpellier JUG)'; }
addSign(msg) => '$msg (from Montpellier JUG)';
addSign(msg) => '$msg (from Montpellier JUG)'; String sayHi(String to, String msg, Function signFct) { return 'Hello $to, ${signFct(msg)}'; } main() { print(sayHi('Dartisans', 'Dart Flight School is awesome',addSign)); }
for(int i = 0; i < list.length; i++) { print(list[i]); }
list.forEach((v) => print(v));
list.forEach(print);
List<int> result = []; List<String> values = ['19','02','2014','19','00']; for(int i = 0; i < values.length; i++) { result.add(int.parse(values[i])); }
['19','02','2014','19','00'].map((String s) { return int.parse(s); });
['19','02','2014','19','00'].map((s) => int.parse(s));
new List.generate(4, (i) => i).reduce((int v, int e) { return v * e; });
new List.generate(4, (i) => i).reduce((v,e) => v+e);
for(int i = 0; i < list.length; i++) { if (list[i] % 2 == 0) { print('$i is even'); } }
list.where((v) => v.isEven).forEach(print);
bool allEven = true; for(int i = 0; i < list.length; i++) { if (list[i] % 2 != 0) { allEvent = false; break; } } if (allEvent) print('Great!');
if (list.every((v) => v.isEven)) print('Great!');
for(int i = 0; i < list.length; i++) { if (list[i] % 2 == 0) { print('Great!'); break; } } if (allEvent) print('Great!');
if (list.any((v) => v.isEven)) print('Great!');
Iterable l1 = [1,2,3,4,5].where((x) => x.isEven); Iterable l2 = l1.map((x) => x*2); Iterable l3 = l2.map((x) => x+1);
[1,2,3,4,5].where((x) => x.isEven) .map((x) => x*2) .map((x) => x+1);
makeAdder(int addBy) { adder(int a) { return a + addBy; } return adder; }
makeAdder(int addBy) => (int a) => a + addBy;
var add100 = makeAdder(100); var result = add100(53); // 153
DateTime today = new DateTime.now(); employees.where((e) => e.name.startsWith('T')) .where((e) => e.birthday == today);
nameStartWith(start) => (e) => e.name.startsWith(start); birthdayIs(when) => (e) => e.birthday == when; employees.where(nameStartWith('T')) .where(birthdayIs(new DateTime.now()));
nameStartWith(start) => (e) => e.name.startsWith(start); birthdayIs(when) => (e) => e.birthday == when; and(List filters) => (e) => filters.every((f) => f(e)); or(List filters) => (e) => filters.any((f) => f(e)); employees.where( and([ birthdayIs(new DateTime.now()), or([ nameStartWith('T'), namesStartWith('A')]) ]) );