日期选择器图像:-
我想关闭日期选择器当有人点击日期然后日期选择器将关闭这里是我的代码
_myDateTime = (await showDatePicker( context: context, initialDate: DateTime.now(), firstDate: DateTime.now(), lastDate: DateTime(2100)))!;
wgeznvg71#
你可以在showDialog上使用CalendarDatePicker小部件。它提供了onDateChanged可以用来关闭对话框并传递selectedDate。
CalendarDatePicker
onDateChanged
_datePicker() async { _myDateTime = await showDialog( context: context, builder: (context) { return LayoutBuilder(builder: (_, constraints) { final width = constraints.maxWidth; final height = constraints.maxHeight; return Center( child: Material( // ok or cancel buttons arent needed for this case, else you can use AlertDialog for general purpose child: SizedBox( width: width * 0.8, // cant managed being expanded child: CalendarDatePicker( initialDate: DateTime.now(), firstDate: DateTime.now(), lastDate: DateTime(2100), onDateChanged: (DateTime value) { Navigator.of(context).pop(value); }, ), ), ), ); }); }, ); debugPrint("selected date is $_myDateTime"); }
1条答案
按热度按时间wgeznvg71#
你可以在showDialog上使用
CalendarDatePicker
小部件。它提供了onDateChanged
可以用来关闭对话框并传递selectedDate。