showVVDatePicker function

Future showVVDatePicker(
  1. BuildContext context, {
  2. required DatePickerType type,
  3. required Function onDone,
  4. DateTime? startTime,
  5. DateTime? endTime,
  6. DateTime? maxTime,
  7. DateTime? minTime,
  8. DateTime? initTime,
  9. CalendarSelectRangeType? rangeSelectType,
  10. bool showTopTitle = true,
  11. bool hasToDate = false,
  12. bool isToDate = false,
  13. String? title,
})

Implementation

Future<dynamic> showVVDatePicker(
  BuildContext context, {
  required DatePickerType type,
  required Function onDone,
  DateTime? startTime,
  DateTime? endTime,
  DateTime? maxTime,
  DateTime? minTime,
  DateTime? initTime,
  CalendarSelectRangeType? rangeSelectType,
  bool showTopTitle = true,
  bool hasToDate = false,
  bool isToDate = false,
  String? title,
}) {
  final String defaultTitle = title ?? "选择时间";

  Widget buildCupertinoPicker() {
    return showTopTitle
        ? MVScrollDatePicker(
            onDone: (DateTime startTime, DateTime? endTime) {
              onDone(startTime, endTime);
            },
            type: type,
            startTime: startTime,
            endTime: endTime,
          )
        : SVScrollDatePicker(
            onDone: hasToDate
                ? (DateTime chooseTime, bool isToDate) {
                    onDone(chooseTime, isToDate);
                  }
                : (DateTime chooseTime) {
                    onDone(chooseTime);
                  },
            type: type,
            time: initTime,
            title: title,
            maxTime: maxTime,
            minTime: minTime,
            hasToDate: hasToDate,
            isToDate: isToDate,
          );
  }

  Widget buildYearMonthPicker() {
    return SizedBox(
      width: MediaQuery.of(context).size.width,
      child: TapDatePicker(
        title: defaultTitle,
        onDone: (DateTime chooseTime) {
          onDone(chooseTime);
        },
        initTime: initTime,
        maxTime: maxTime,
      ),
    );
  }

  switch (type) {
    case DatePickerType.SINGLE_YMD:
    case DatePickerType.YMDWHM:
    case DatePickerType.scrollYMDWHM:
    case DatePickerType.scrollYMD:
      return showCupertinoModalPopup(
        context: context,
        barrierColor: const Color(0x80000000),
        builder: (BuildContext context) => buildCupertinoPicker(),
      );
    case DatePickerType.yearMonth:
    case DatePickerType.tapYM:
      return showModalBottomSheet(
        context: context,
        barrierColor: const Color.fromRGBO(0, 0, 0, 0.7),
        isScrollControlled: true,
        enableDrag: false,
        backgroundColor: Colors.transparent,
        builder: (context) => buildYearMonthPicker(),
      );
    default:
      return Future(() => null);
  }
}