flutter日期時間選擇器的代碼怎么寫,針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
1 日期選擇器
//設(shè)置默認顯示的日期為當前 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 時間選擇器
//設(shè)置顯示顯示的時間為當前 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; }); } }
關(guān)于flutter日期時間選擇器的代碼怎么寫問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。