Age verification based on gender

Widgets & Design

I'm developing an matrimonial app, as per Indian law men should be of the age 21 and women should be at least 18 years of age,

now coming to issue, how do I set the calendar widget in flutter flow such that it doesn't show any dates after the minimum age required

I have created a custom function which takes the gender as an argument and returns the minimum date which is required.

but I'm not able to set the Minimum date/time in the calender widget so that it dosent show andy values after the min date

for example if the date is 30/06/2024, it should not allow any date after 30/062003.

how do I set this up?

What have you tried so far?
import 'dart:convert';
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;
import '/flutter_flow/lat_lng.dart';
import '/flutter_flow/place.dart';
import '/flutter_flow/uploaded_file.dart';
import '/flutter_flow/custom_functions.dart';
import '/backend/backend.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import '/auth/firebase_auth/auth_util.dart';

DateTime? getMinDate(String? gender) {
  /// MODIFY CODE ONLY BELOW THIS LINE

  if (gender == null) {
    return null;
  }

  DateTime currentDate = DateTime.now();
  DateTime minDate;

  if (gender.toLowerCase() == "female") {
    minDate = currentDate.subtract(Duration(days: 365 * 18));
  } else if (gender.toLowerCase() == "male") {
    minDate = currentDate.subtract(Duration(days: 365 * 21));
  } else {
    return null;
  }

  return minDate;

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