showDateRangePicker static method
Future
showDateRangePicker({
- 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? startTitle,
- Widget? endTitle,
- TextStyle? itemTextStyle,
- Widget? actions,
- dynamic callBack()?,
展示选择器基础示例,不满足样式外部更加DatePicker可自定义你的窗口 开始时间--结束时间 -dialog
Implementation
///开始时间--结束时间 -dialog
static Future<dynamic> showDateRangePicker(
{
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? startTitle,
Widget? endTitle,
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: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)),
),
),
),
),
)
);
},
);
}