我在 Flutter 中使用 timePicker。
一旦我从弹出对话框中选择了时间,它就会显示选择的时间,但它不仅会显示时间,例如:12:45
,还会显示 TimeOfDay,例如:TimeOfDay (12:45)
。
如何去掉 TimeOfDay 文本?
//Declaration example
TimeOfDay _time = new TimeOfDay.now();
//Time picker example code
Future<Null> _selectTime(BuildContext context) async {
final TimeOfDay picked = await showTimePicker(context: context, initialTime: _time);`
if (picked != null && picked != _time) {
print('${_time.toString()}');
setState(() {
_time = picked;
});
}
}
//Display example
Text(
'${_time.toString()}',
),
我希望时间看起来像:12:45
而不是:TimeOfDay(12:45)
。
最佳答案
这将以所需格式打印。
Text(
_time.format(context),
),
关于flutter - 在 Flutter 中从 timePicker 选择时间后如何删除 TimeOfDay 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56682711/