showVVDatePicker function
Future
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,
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);
}
}