Anyone knows how I can use the AM/PM format of the time picker in any language?
The app has english & romanian languages, when in romanian the time picker it uses the 24 hour format, though I need AM/PM.
我没有找到任何方法来设置它的区域设置,所以我有点卡住了.
Anyone knows how I can use the AM/PM format of the time picker in any language?
The app has english & romanian languages, when in romanian the time picker it uses the 24 hour format, though I need AM/PM.
我没有找到任何方法来设置它的区域设置,所以我有点卡住了.
由于菲利普没有编辑他的答案,我会自己把答案和解决方案放在一起.
showTimePicker需要在函数的builder方法中将alwaysUse24HourFormat设置为true,并将区域设置更改为en US.
没有任何一个都做不到.
因此,正确的解决方案是:
showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
builder: (BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: false),
child: Localizations.override(
context: context,
locale: const Locale('en', 'US'),
child: child!,
),
),
);
还有一个公开的Github问题,for this issue.