calculateAge static method

int calculateAge(
  1. DateTime? birthDate
)

Implementation

static int calculateAge(DateTime? birthDate) {
  if (birthDate == null) return 0;
  final now = DateTime.now();
  int age = now.year - birthDate.year;
  if (now.month < birthDate.month ||
      (now.month == birthDate.month && now.day < birthDate.day)) {
    age--;
  }
  return age;
}