calculateAge property

int get calculateAge

The calculateAge property calculates the age of a person based on their birthdate. It takes the current date into account and returns the person's age in years.

Implementation

int get calculateAge {
  final today = DateTime.now();
  int age = today.year - year;

  if (today.month < month || (today.month == month && today.day < day)) {
    age--;
  }

  return age;
}