Dart For Flutter Cheat Sheet PDF
Dart For Flutter Cheat Sheet PDF
cc-by Mobile App Development with Google’s Flutter and Firebase: from Zero to Hero https://github.com/FlutterInThai
Dart for Flutter Cheat Sheet 2
Classes Abstract classes
class Point { abstract class Doer {
num x, y;
// static variable
void doSomething();
static const fixedNumber = 16; }
// constructor class EffectiveDoer extends Doer {
Point(this.x, this.y); void doSomething() {
// named constructor print('something');
Point.origin() {
x = 0;
}
y = 0; }
} class Greeter implements
// initializer constructor EffectiveDoer {
Point.fromJson(Map<String, num> json) doSomething () {
: x = json['x'], print('Hello');
y = json['y'] { }
print('In Point.fromJson(): ($x, $y)'); }
}
}
// invoking non-default constructor Mixins
class Employee extends Person { // multiple class hierarchies
Employee.fromJson(Map data) : class Musician extends Performer with
super.fromJson(data) { Musical, Conductor, Composer {
// do something }
} mixin Musical {
} bool canPlayPiano = true;
// factory constructors void entertainMe() {
class Logger {
print('Playing piano');
final String name;
bool mute = false; }
}
static final Map<String, Logger> _cache =
<String, Logger>{};
Asynchrony
factory Logger(String name) {
if (_cache.containsKey(name)) {
Future checkVersion() async {
return _cache[name]; try {
} else {
version = await lookUpVersion();
final logger =
Logger._internal(name); } catch (e) {
_cache[name] = logger; Print(e.toString);
return logger;
} }
} // Do something with version
Logger._internal(this.name); }
cc-by Mobile App Development with Google’s Flutter and Firebase: from Zero to Hero https://github.com/FlutterInThai