calculateAge static method

int calculateAge({
  1. required DateTime birthDate,
})

Implementation

static int calculateAge({required DateTime birthDate}) {
  DateTime today = DateTime.now();
  int age = today.year - birthDate.year;

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

  return age;
}