Skip to content

Instantly share code, notes, and snippets.

@nmccready
Last active August 19, 2021 03:22
Show Gist options
  • Save nmccready/00d11c8a7974510c67515e323beabc61 to your computer and use it in GitHub Desktop.
Save nmccready/00d11c8a7974510c67515e323beabc61 to your computer and use it in GitHub Desktop.
Dart Notes
void main() {
final p = new Employee("Nick", height: 5.8, weight: 210, age: 41, taxCode: "123", salary: 2000000);
print(p.toString());
}
mixin Health {
String getLifePercentage(int age) => (100 * (age / 101.00)).toStringAsFixed(3);
double getBMI(double height, double weight) => weight / (height * height);
}
class Person with Health {
final String name;
final int age;
final double height;
final double weight;
Person(this.name, { this.age, this.height, this.weight = 0.0 });
String toString() => "name: $name, age: $age, height: $height, bmi: $bmi, life: $lifePercent";
double get bmi => getBMI(this.height, this.weight);
String get lifePercent => getLifePercentage(this.age);
}
class Employee extends Person {
final String taxCode;
final int salary;
Employee(String name, {int age, double height, double weight, this.taxCode, this.salary}) :
super(name, age: age, height: height, weight: weight);
String toString() => "${super.toString()} taxCode: $taxCode, salary: $salary";
}
@nmccready
Copy link
Author

Mixins are kinda slick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment