showDateModalBottomSheet static method

Future showDateModalBottomSheet({
  1. required BuildContext context,
  2. required DateController controller,
  3. bool barrierDismissible = true,
  4. double height = 500,
  5. int totalYears = 110,
  6. int forwardYears = 50,
  7. double vGap = 16,
  8. BoxDecoration? pickerDecoration,
  9. DateTime? initStartDate,
  10. DateTime? initEndDate,
  11. double pickerVisibilityHeight = 140,
  12. double itemExtent = 40,
  13. double maskHeight = 40,
  14. double itemWidth = 100,
  15. double maskRadius = 0,
  16. double? diameterRatio,
  17. Color? backgroundColor,
  18. double? offAxisFraction,
  19. bool? useMagnifier,
  20. double? magnification,
  21. double? squeeze,
  22. Widget? selectionOverlay,
  23. Widget? title,
  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. Color? bottomSheetBackgroundColor,
  30. String? barrierLabel,
  31. double? elevation,
  32. ShapeBorder? shape,
  33. Clip? clipBehavior,
  34. BoxConstraints? constraints,
  35. Color? barrierColor,
  36. bool isScrollControlled = false,
  37. double scrollControlDisabledMaxHeightRatio = 9.0 / 16.0,
  38. bool useRootNavigator = false,
  39. bool isDismissible = true,
  40. bool enableDrag = true,
  41. bool? showDragHandle,
  42. bool useSafeArea = false,
  43. RouteSettings? routeSettings,
  44. AnimationController? transitionAnimationController,
  45. Offset? anchorPoint,
  46. AnimationStyle? sheetAnimationStyle,
  47. TextStyle? itemTextStyle,
  48. Widget? actions,
  49. dynamic callBack(
    1. DateTime? startDate,
    2. DateTime? endDate
    )?,
})

选择某个日期-时间

Implementation

static Future<dynamic> showDateModalBottomSheet({
  required BuildContext context,
  required DateController controller,
  bool barrierDismissible = true,
  double height = 500,
  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,
  Widget? title,
  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,
  Color? bottomSheetBackgroundColor,
  String? barrierLabel,
  double? elevation,
  ShapeBorder? shape,
  Clip? clipBehavior,
  BoxConstraints? constraints,
  Color? barrierColor,
  bool isScrollControlled = false,
  double scrollControlDisabledMaxHeightRatio =  9.0 / 16.0,
  bool useRootNavigator = false,
  bool isDismissible = true,
  bool enableDrag = true,
  bool? showDragHandle,
  bool useSafeArea = false,
  RouteSettings? routeSettings,
  AnimationController? transitionAnimationController,
  Offset? anchorPoint,
  AnimationStyle? sheetAnimationStyle,
  TextStyle? itemTextStyle,
  Widget? actions,
  Function(DateTime? startDate, DateTime? endDate)? callBack,
}) {
  final strings = datePickerStrings ?? DatePickerStrings.fromLocale(Localizations.localeOf(context));
  return showModalBottomSheet(
    context: context,
    backgroundColor: bottomSheetBackgroundColor,
    barrierLabel: barrierLabel,
    elevation: elevation,
    shape: shape,
    clipBehavior: clipBehavior,
    constraints: constraints ?? BoxConstraints(maxWidth: MediaQuery.of(context).size.width),
    barrierColor: barrierColor,
    isScrollControlled: true,
    scrollControlDisabledMaxHeightRatio: scrollControlDisabledMaxHeightRatio,
    useRootNavigator: useRootNavigator,
    isDismissible: isDismissible,
    enableDrag: enableDrag,
    showDragHandle: showDragHandle,
    useSafeArea: useSafeArea,
    routeSettings: routeSettings,
    transitionAnimationController: transitionAnimationController,
    anchorPoint: anchorPoint,
    sheetAnimationStyle: sheetAnimationStyle,
    builder: (context) {
      return 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) {
            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)),
            ),
          ),
        ),
      );
    },
  );
}