showDateRangeModalBottomSheet static method

Future showDateRangeModalBottomSheet({
  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. Color? maskColor = const Color.fromRGBO(242, 242, 244, 0.7),
  24. Duration duration = const Duration(milliseconds: 200),
  25. Curve curve = Curves.easeInOutCubic,
  26. List<DateType> showColumn = const [DateType.year, DateType.month, DateType.day, DateType.hour, DateType.minute, DateType.second],
  27. DatePickerStrings? datePickerStrings,
  28. Color? bottomSheetBackgroundColor,
  29. String? barrierLabel,
  30. double? elevation,
  31. ShapeBorder? shape,
  32. Clip? clipBehavior,
  33. BoxConstraints? constraints,
  34. Color? barrierColor,
  35. bool isScrollControlled = false,
  36. double scrollControlDisabledMaxHeightRatio = 9.0 / 16.0,
  37. bool useRootNavigator = false,
  38. bool isDismissible = true,
  39. bool enableDrag = true,
  40. bool? showDragHandle,
  41. bool useSafeArea = false,
  42. RouteSettings? routeSettings,
  43. AnimationController? transitionAnimationController,
  44. Offset? anchorPoint,
  45. AnimationStyle? sheetAnimationStyle,
  46. Widget? startTitle,
  47. Widget? endTitle,
  48. TextStyle? itemTextStyle,
  49. Widget? actions,
  50. dynamic callBack(
    1. DateTime? startDate,
    2. DateTime? endDate
    )?,
})

开始时间--结束时间 -BottomSheet

Implementation

static Future<dynamic> showDateRangeModalBottomSheet({
      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,
      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,
      Widget? startTitle,
      Widget? endTitle,
      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: startTitle?? Padding( // Using strings.startDate
          padding: const EdgeInsets.only(left: 20),
          child: Text(strings.startDate,
              style: const TextStyle(
                  color: Colors.black,
                  fontSize: 14,
                  fontWeight: FontWeight.bold)),
        ),
        endWidget: endTitle??Padding( // Using strings.endDate
          padding: const EdgeInsets.only(left: 20),
          child: Text(strings.endDate,
              style: const TextStyle(
                  color: Colors.black,
                  fontSize: 14,
                  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(
              margin: const EdgeInsets.only(top: 30),
              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)),
            ),
          ),
        ),
      );
    },
  );
}