[英]The value extracted from showTimePicker Flutter
I created a showTimePicker and I changed the format in 24h, but when I am extracting the value in the ".then" future I get the time in 12h format.我创建了一个 showTimePicker 并在 24 小时内更改了格式,但是当我在“.then”未来中提取值时,我获得了 12 小时格式的时间。 Can somebody tell me where is the issue?
有人能告诉我问题出在哪里吗? This is the code:
这是代码:
void _presentTimePicker() {
showTimePicker(
context: context,
initialTime: TimeOfDay(
hour: TimeOfDay.now().hour,
minute: (TimeOfDay.now().minute - TimeOfDay.now().minute % 10 + 10)
.toInt()),
builder: (BuildContext context, Widget child) {
return MediaQuery(
data:
MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
child: child);
}).then((value) {
if (value == null) return;
setState(() {
time.text = TimeOfDay(
hour: value.hour,
minute: value.minute,
).format(context);
print(time.text);
});
});
} }
the output is: 5:50 PM when I selected in picker 17:50输出是:当我在选择器 17:50 中选择时的下午 5:50
This issue is how you are changing the time of day back to a string.这个问题是如何将一天中的时间改回字符串。 Try using this instead, so that you can override the default.
尝试改用它,以便您可以覆盖默认值。
localizations.formatTimeOfDay(TimeOfDay(
hour: value.hour,
minute: value.minute,
), alwaysUse24HourFormat: true);
(The default is derived from MediaQuery
- see here for more details of how.) (默认值源自
MediaQuery
- 有关详细信息,请参见此处。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.