//only classes that extend or implement the Musician class //can use the mixin Song mixin Song on Musician { void play() { print('-------playing------'); }
void stop() { print('....stopping.....'); } }
//To use a mixin, use the with keyword followed by one or more mixin names classPerformSongextendsMusicianwithFeedback, Song{ //Because PerformSong extends Musician, //PerformSong can mix in Song void awesomeSong() { play(); clap(); }
typedef IntList = List<int>; List<int> i1=[1,2,3]; // normal way. IntList i2 = [1, 2, 3]; // Same thing but shorter and clearer.
//type alias can have type parameters typedef ListMapper<X> = Map<X, List<X>>; Map<String, List<String>> m1 = {}; // normal way. ListMapper<String> m2 = {}; // Same thing but shorter and clearer.
String joinWithCommas(int a, [int? b, int? c, int? d, int e = 100]) { var total = '$a'; if (b != null) total = '$total,$b'; if (c != null) total = '$total,$c'; if (d != null) total = '$total,$d'; total = '$total,$e'; return total; }
void main() { var result = joinWithCommas(1, 2); print(result); }