Skip to content

Instantly share code, notes, and snippets.

@marcel-ploch
Created April 13, 2022 18:43
Show Gist options
  • Save marcel-ploch/7f53b30543b0e17735873ad3edc4c64c to your computer and use it in GitHub Desktop.
Save marcel-ploch/7f53b30543b0e17735873ad3edc4c64c to your computer and use it in GitHub Desktop.
class Vehicle {
String? make;
String? model;
int? manufactureYear;
int? vehicleAge;
String? color;
int get age {
return vehicleAge ?? 0;
}
void set age(int currentYear) {
vehicleAge = currentYear - (manufactureYear ?? 2020);
}
// We can also eliminate the setter and just use a getter.
//int get age {
// return DateTime.now().year - manufactureYear;
//}
Vehicle({this.make,this.model,this.manufactureYear,this.color,});
}
void main() {
Vehicle v = Vehicle();
v.age = 2022;
print(v.age);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment