我做过这样的事情,它接受用户的日期和时间,但是我没有得到如何限制用户选择当前日期的日期和时间的方法。
这是我的代码,
class _DateTimePickerExampleState extends State<DateTimePickerExample> {
DateTime date1;
DateTime date2;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('DateTime Picker Example'),
),
body: Padding(
padding: EdgeInsets.all(16.0),
child: ListView(
children: <Widget>[
DateTimePickerFormField(
inputType: InputType.both,
format: DateFormat("EEEE, MMMM d, yyyy 'at' h:mma"),
editable: false,
decoration: InputDecoration(
labelText: 'From',
hasFloatingPlaceholder: false
),
initialValue: DateTime.now(),
onChanged: (dt) {
setState(() => date1 = dt);
print('Selected date: $date1');
},
),
DateTimePickerFormField(
inputType: InputType.both,
format: DateFormat("EEEE, MMMM d, yyyy 'at' h:mma"),
editable: false,
decoration: InputDecoration(
labelText: 'To',
hasFloatingPlaceholder: false
),
onChanged: (dt) {
setState(() => date2 = dt);
print('Selected date: $date2');
},
),
SizedBox(height: 16.0),
],
),
)
);
}