1 日期选择器
//设置默认显示的日期为当前
DateTime initialDate = DateTime.now();
void showDefaultYearPicker(BuildContext context) async {
final DateTime dateTime = await showDatePicker(
context: context,
//定义控件打开时默认选择日期
initialDate: initialDate,
//定义控件最早可以选择的日期
firstDate: DateTime(2018, 1),
//定义控件最晚可以选择的日期
lastDate: DateTime(2022, 1),
builder: (BuildContext context, Widget child) {
return Theme(
data: CommonColors.themData,
child: child,
);
},
);
if (dateTime != null && dateTime != initialDate) {}
}
2 时间选择器
//设置显示显示的时间为当前
TimeOfDay initialTime = TimeOfDay.now();
void showDefaultDatePicker(BuildContext context) async {
final TimeOfDay timeOfDay = await showTimePicker(
context: context,
initialTime: initialTime,
builder: (BuildContext context, Widget child) {
return Theme(
data: CommonColors.themData,
child: child,
);
},
);
if (timeOfDay != null && timeOfDay != initialTime) {
setState(() {
initialTime = timeOfDay;
});
}
}
本公众号会首发系列专题文章,付费的视频课程会在公众号中免费刊登,在你上下班的路上或者是睡觉前的一刻,本公众号都是你浏览知识干货的一个小选择,收藏不如行动,在那一刻,公众号会提示你该学习了。
只要用心去做,每一件事情还是有可能成功的,当然成功是没有界限的,只不过是达到自己心里的那个目标,公众号:我的大前端生涯,一个爱喝茶的程序员,通常会搞搞SpringBoot 、Herbinate、Mybatiys、Android、iOS、Flutter、Vue、小程序等.