Created
April 13, 2022 18:43
-
-
Save marcel-ploch/7f53b30543b0e17735873ad3edc4c64c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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