BEST WAY TO SET BIRTHDATE AND GET THE AGE IN FF v2

Custom Code

Following this previous question :

Hi, I'm looking how to set birthday in FF and relate this with age of user (so the platform can update the age every year). I was thinking use 3 fields (month, year and day) and user can fill them. After, apply a custom function to calculate the age according the current time.

I'm now using a custom function that properly work :

 final now = DateTime.now();
 int age = now.year - date.year;

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

  return age;

My problem is :

When the age is bellow 1 year, the returned age is "0", what i would like is to get as a return "<1"
I have almost 0 knowledge in coding and have tried various things but always ended up with wrong result.

Thank you for your help and time.

What have you tried so far?
String? getAgeFromDateTimePickerCopy(DateTime date) {
  /// MODIFY CODE ONLY BELOW THIS LINE

  final now = DateTime.now();
  int age = now.year - date.year;

  if (now.month < date.month ||
      (now.month == date.month && now.day < date.day)) {
    age--;
    if (age < 1) {
      return '<1';
    }
  }
  return age.toString();

  /// MODIFY CODE ONLY ABOVE THIS LINE
}
Did you check FlutterFlow's Documentation for this topic?
Yes
2 replies