我创造了自己的
Widget
其中包括
DatePicker
,这里是代码:
class DatePicker extends StatelessWidget {
final Icon icon;
final DateTime initialDate;
final ValueChanged<DateTime> onDateSelected;
DatePicker({this.icon = const Icon(Icons.date_range), @required this.initialDate, this.onDateSelected});
Future<Null> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(context: context, initialDate: initialDate, firstDate: DateTime(2015, 8), lastDate: DateTime(2101));
if (picked != null && picked != initialDate) {
// TODO: return the picked value in the 'OnDateSelect' callback
print(picked.toString());
}
}
@override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
Text(initialDate.toString()),
IconButton(
icon: this.icon,
onPressed: () => _selectDate(context),
)
],
);
}
}
我想这样使用它:
DatePicker(
initialDate: _ticketDate,
onDateSelected: (newDate) {
print(newDate);
},
);
我不知道的是如何返回在自定义中选择的日期
onDateSelected
回拨一次
Future<Null>
_selectDate
已经被处决。
有什么想法吗?