How do I call on the super class' constructor and other statements in Dart?
If you want execute code before the super
you can do it like that:
abstract class Animal {
String name;
Animal (this.name);
}
class Cat extends Animal {
String breed;
Cat(int i):
breed = breedFromCode(i),
super(randomName());
static String breedFromCode(int i) {
// ...
}
static String randomName() {
// ...
}
}
You can call super
in this way:
abstract class Animal {
String name;
Animal (String this.name);
}
class Dog extends Animal {
Dog() : super('Spot') {
print("Dog was created");
}
}
void main() {
var d = new Dog(); // Prints 'Dog was created'.
print(d.name); // Prints 'Spot'.
}