一、Flutter日期组件:
var _datetime=DateTime.now();
_showDatePicker() async{
var date =await showDatePicker(
context: context,
initialDate: _datetime,
firstDate:DateTime(1900),
lastDate:DateTime(2050)
);
if(date==null) return;
print(date);
setState(() {
_datetime=date!;
});
}
二、Flutter时间组件:
var _time=TimeOfDay(hour: 9,minute: 20);
_showTimePicker() async{
var time =await showTimePicker(
context: context,
initialTime: _time
);
if(time==null) return;
print(time);
setState(() {
this._time=time!;
});
}
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Row(
children: <Widget>[
Text("${formatDate(_datetime, [yyyy, '-', mm, '-', dd])}"),
Icon(Icons.arrow_drop_down)
],
),
onTap: _showDatePicker,
),
InkWell(
child: Row(
children: <Widget>[
Text("${this._time.format(context)}"),
Icon(Icons.arrow_drop_down)
],
),
onTap: _showTimePicker,
),
],
)
],
)