age property
int
get
age
Returns the age in years.
Example:
DateTime(2000, 1, 1).age; // 24 (if current year is 2024)
Implementation
int get age {
final now = DateTime.now();
int age = now.year - year;
if (now.month < month || (now.month == month && now.day < day)) {
age--;
}
return age;
}