更多文章请查看 lutter从入门 到精通
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; }); } }本公众号会首发系列专题文章,付费的视频课程会在公众号中免费刊登,在你上下班的路上或者是睡觉前的一刻,本公众号都是你浏览知识干货的一个小选择,收藏不如行动,在那一刻,公众号会提示你该学习了。