showDatePicker static method

Future showDatePicker({
  1. required BuildContext context,
  2. required DateController controller,
  3. bool barrierDismissible = true,
  4. double height = 500,
  5. double width = 400,
  6. int totalYears = 110,
  7. int forwardYears = 50,
  8. double vGap = 16,
  9. BoxDecoration? pickerDecoration,
  10. DateTime? initStartDate,
  11. DateTime? initEndDate,
  12. double pickerVisibilityHeight = 140,
  13. double itemExtent = 40,
  14. double maskHeight = 40,
  15. double itemWidth = 100,
  16. double maskRadius = 0,
  17. double? diameterRatio,
  18. Color? backgroundColor,
  19. double? offAxisFraction,
  20. bool? useMagnifier,
  21. double? magnification,
  22. double? squeeze,
  23. Widget? selectionOverlay,
  24. Color? maskColor = const Color.fromRGBO(242, 242, 244, 0.7),
  25. Duration duration = const Duration(milliseconds: 200),
  26. Curve curve = Curves.easeInOutCubic,
  27. List<DateType> showColumn = const [DateType.YEAR, DateType.MONTH, DateType.DAY, DateType.HOUR, DateType.MINUTE, DateType.SECOND],
  28. DatePickerStrings? datePickerStrings,
  29. Widget? title,
  30. TextStyle? itemTextStyle,
  31. Widget? actions,
  32. dynamic callBack(
    1. DateTime? startDate,
    2. DateTime? endDate
    )?,
})

Implementation

static Future<dynamic> showDatePicker(
    {
      required BuildContext context,
      required DateController controller,
      bool barrierDismissible = true,
      double height = 500,
      double width = 400,
      int totalYears = 110,
      int forwardYears = 50,
      double vGap = 16,
      BoxDecoration? pickerDecoration,
      DateTime? initStartDate,
      DateTime? initEndDate,
      double pickerVisibilityHeight = 140,
      double itemExtent = 40,
      double maskHeight = 40,
      double itemWidth = 100,
      double maskRadius = 0,
      double? diameterRatio,
      Color? backgroundColor,
      double? offAxisFraction,
      bool? useMagnifier,
      double? magnification,
      double? squeeze,
      Widget? selectionOverlay,
      Color? maskColor = const Color.fromRGBO(242, 242, 244, 0.7),
      Duration duration = const Duration(milliseconds: 200),
      Curve curve = Curves.easeInOutCubic,
      List<DateType> showColumn = const [
        DateType.YEAR,
        DateType.MONTH,
        DateType.DAY,
        DateType.HOUR,
        DateType.MINUTE,
        DateType.SECOND
      ],
      DatePickerStrings? datePickerStrings,
      Widget? title,
      TextStyle? itemTextStyle,
      Widget? actions,
      Function(DateTime? startDate, DateTime? endDate)? callBack,
    }) {
  final strings = datePickerStrings ?? DatePickerStrings.fromLocale(Localizations.localeOf(context));
  return showDialog(
    context: context,
    barrierDismissible: barrierDismissible,
    builder: (context) {
      return Center(child:
      SizedBox(
        width: width,
        child: DatePicker(
          controller: controller,
          pickerDecoration: pickerDecoration,
          height: height,
          totalYears: totalYears,
          initStartDate: initStartDate,
          initEndDate: initEndDate,
          forwardYears: forwardYears,
          vGap: vGap,
          pickerVisibilityHeight: pickerVisibilityHeight,
          itemExtent: itemExtent,
          itemWidth: itemWidth,
          maskHeight: maskHeight,
          maskRadius: maskRadius,
          maskColor: maskColor,
          diameterRatio: diameterRatio,
          backgroundColor: backgroundColor,
          offAxisFraction: offAxisFraction,
          useMagnifier: useMagnifier,
          magnification: magnification,
          squeeze: squeeze,
          selectionOverlay: selectionOverlay,
          duration: duration,
          curve: curve,
          showColumn: showColumn,
          startWidget:title?? Padding( // Using strings.startDate
            padding: const EdgeInsets.only(left: 20),
            child: Text(strings.pleaseSelect,
                style: const TextStyle(
                    color: Colors.black,
                    fontSize: 18,
                    fontWeight: FontWeight.bold)),
          ),
          itemBuilder: (type, value) {
            String label = '';
            switch (type) { // Using strings for year, month, day, etc.
              case DateType.YEAR:
                label = strings.year;
                break;
              case DateType.MONTH:
                label = strings.month;
                break;
              case DateType.DAY:
                label = strings.day;
                break;
              case DateType.HOUR:
                label = strings.hour;
                break;
              case DateType.MINUTE:
                label = strings.minute;
                break;
              case DateType.SECOND:
                label = strings.second;
                break;
            }
            return Center(
              child: Text(
                "$value$label",
                style:itemTextStyle?? const TextStyle(
                    color: Color.fromRGBO(21, 21, 21, 1),
                    fontSize: 16,
                    fontWeight: FontWeight.bold),
              ),
            );
          },
          action: actions??GestureDetector(
            onTap: () {
              final startDate = controller.getStartDate();
              final endDate = controller.getEndDate();
              callBack?.call(startDate, endDate);
              Navigator.pop(context, [startDate, endDate]);
            },
            child: Center(
              child: Container(
                padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
                decoration: BoxDecoration(
                  color: Colors.lightBlueAccent,
                  borderRadius: BorderRadius.circular(20),
                ),
                child: Text(strings.confirm, // Using strings.confirm
                    style: const TextStyle(color: Colors.white, fontSize: 16)),
              ),
            ),
          ),
        ),
      )
      );
    },
  );
}