datePicker static method

dynamic datePicker({
  1. required BuildContext context,
  2. bool? futureDates,
  3. bool? pastDates,
  4. String? locale,
  5. DateTime? firstDate,
})

Implementation

static datePicker(
    {required BuildContext context,
    bool? futureDates,
    bool? pastDates,
    String? locale,
    DateTime? firstDate}) async {
  final currentDate = DateTime.now();
  final localeObj = locale != null ? Locale(locale) : null;
  final selected = await showDatePicker(
    context: context,
    lastDate: futureDates! ? DateTime(2150) : currentDate,
    initialDate: firstDate ?? currentDate,
    firstDate: pastDates! ? DateTime(200) : firstDate ?? currentDate,
    locale: localeObj,
    builder: (context, child) {
      return Theme(
        data: ThemeData.dark().copyWith(
            colorScheme: ColorScheme.fromSwatch(),
            dialogBackgroundColor: Colors.blue,
            textButtonTheme: TextButtonThemeData(
                style: TextButton.styleFrom(
                    textStyle: TextStyle(
                        color: Colors.blue,
                        fontWeight: FontWeight.normal,
                        fontSize: 12,
                        fontFamily: 'Poppins'),
                    foregroundColor: Colors.blue,
                    backgroundColor: Colors.blue,
                    shape: RoundedRectangleBorder(
                        side: const BorderSide(
                            color: Colors.transparent,
                            width: 1,
                            style: BorderStyle.solid),
                        borderRadius: BorderRadius.circular(50))))),
        child: child!,
      );
    },
  );

  if (selected != null) {
    selectedDate = selected;
  } else {
    selectedDate = null;
  }
  return selectedDate;
}