age property

int get age

Implementation

int get age {
  DateTime currentDate = DateTime.now();
  int ageInYears = currentDate.year - year;
  int ageInMonths = currentDate.month - month;

  if (currentDate.day < day) {
    ageInMonths--;
  }

  if (ageInMonths < 0) {
    ageInYears--;
    ageInMonths += 12;
  }

  return ageInYears;
}