dateSelect static method
Future<DateTime?>
dateSelect(
- BuildContext context, {
- DateTime? selectedDate,
- DateTime? firstDate,
- DateTime? lastDate,
- DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
- DatePickerMode initialDatePickerMode = DatePickerMode.day,
- DateFiltering? dateFiltering,
- String helpText = "Select date",
- String cancelText = "Cancel",
- String confirmText = "Confirm",
- String invalidText = "Enter a valid date",
- String fieldLabelText = "Date",
- String fieldHintText = "yyyy/mm/dd",
- DateSelectListener? selectListener,
Implementation
static Future<DateTime?> dateSelect(
BuildContext context, {
DateTime? selectedDate,
DateTime? firstDate,
DateTime? lastDate,
DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
DatePickerMode initialDatePickerMode = DatePickerMode.day,
DateFiltering? dateFiltering,
String helpText = "Select date",
String cancelText = "Cancel",
String confirmText = "Confirm",
String invalidText = "Enter a valid date",
String fieldLabelText = "Date",
String fieldHintText = "yyyy/mm/dd",
DateSelectListener? selectListener}) async{
log("NUIDTUtil -> Showing date picker");
late Future<DateTime?> dateTime;
DateTime initialDate;
final mySelectedDate = selectedDate ?? DateTime.now();
if(lastDate != null && mySelectedDate.isAfter(lastDate)){
initialDate = lastDate;
}
else if(firstDate != null && firstDate.isAfter(mySelectedDate)){
initialDate = firstDate;
}
else{
initialDate = mySelectedDate;
}
if(Platform.isIOS){
final datePicker = CupertinoDatePicker(
onDateTimeChanged: (date) async{
if(selectListener != null){
selectListener(date);
}
dateTime = NUIAsync.delayForResult(Duration(milliseconds: 100), () async{
return date;
});
},
initialDateTime: mySelectedDate,
minimumDate: firstDate ?? DateTime(DateTime.now().year - 100),
maximumDate: lastDate ?? DateTime(DateTime.now().year + 100),
mode: CupertinoDatePickerMode.date,
);
showNUIBottomSheet(context: context, content: (context){
return Container(
height: screenHeight(context)/3,
color: NUIColors.NUIWhite,
child: datePicker,
);
});
}
else {
dateTime = showDatePicker(
context: context,
initialDate: initialDate,
firstDate: firstDate ?? DateTime(DateTime.now().year - 100),
lastDate: lastDate ?? DateTime(DateTime.now().year + 100),
initialEntryMode: initialEntryMode,
initialDatePickerMode: initialDatePickerMode,
selectableDayPredicate: dateFiltering,
helpText: helpText,
confirmText: confirmText,
cancelText: cancelText,
errorFormatText: "Enter a valid date",
errorInvalidText: invalidText,
fieldLabelText: fieldLabelText,
fieldHintText: fieldHintText,
);
}
final dateResult = await dateTime;
if(selectListener != null){
selectListener(dateResult);
}
return dateResult;
}