【发布时间】:2022-01-21 14:20:08
【问题描述】:
1.这是第一个代码:
DateTime? _selectedTime;
void _datePicker(BuildContext con2) {
showDatePicker(
initialDate: DateTime.utc(2021, 12, 21),
firstDate: DateTime(2000),
lastDate: DateTime.now(),
context: con2,
// ignore: non_constant_identifier_names
).then((UserSelect) {
if (UserSelect == null) {
return;
}
setState(() {
UserSelect = _selectedTime;
});
});
}
2.这是第二个:
body: Container(
color: Colors.black,
height: double.infinity,
child: Center(
child: ElevatedButton(
onPressed: () {
_datePicker(context);
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.purple)),
child: Text(
'${DateFormat('yyyy/MM/dd').format(_selectedTime!)}',
【问题讨论】:
标签: dart flutter-test dart-null-safety