问题描述
我想在我的应用程序中实现提醒功能,该功能可以提醒用户在选定的时间执行特定的任务.我已经实现了 showDatePicker
小部件以选择日期和月份,但是我不确定在 showDatePicker
showTimePicker .>
I want to implement a reminder feature in my application which reminds the user to do a particular task at a selected time. I have implemented a showDatePicker
widget to select the date and month but i am unsure on how to display a showTimePicker
after a date is selected in the showDatePicker
我可以对如何实施提出建议吗?
Could i get a suggestion on how this can be implemented?
代码:
_selectDate() async {
final DateTime picker =await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2010),
lastDate: DateTime(2040)
);
if (picker != null) {
print(picker);
_daysPageController.jumpToDay(picker);
// Navigator.pop(context);
// print(selectedDate);
// await runJump(selectedDate);
// return selectedDate;
}
}
推荐答案
它非常简单,它创建了一个单个函数,该函数依次调用了showDatePicker()和showTimePicker()方法.
It is very simple, it creates a single function that in sequence calls the methods showDatePicker() and showTimePicker().
Future _selectDayAndTime(BuildContext context) async {
DateTime _selectedDay = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2018),
lastDate: DateTime(2030),
builder: (BuildContext context, Widget child) => child
);
TimeOfDay _selectedTime = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
);
if(_selectedDay != null && _selectedTime != null) {
//a little check
}
}
这篇关于在flutter中的showDatePicker上设置日期后如何显示showTimePicker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!