gpt4 book ai didi

flutter - Web 应用程序的语言环境始终为 'en' Flutter

转载 作者:行者123 更新时间:2023-12-04 01:27:16 37 4
gpt4 key购买 nike

我的应用程序可以正确地从 Android 和 iOS 获取设备语言环境,但不能从网络获取。我得到的网络区域设置语言代码为 ui.window.locale.languageCode使用 ui.dart包裹。在我的 Mac 中,我将系统语言设置为意大利语,时区设置为意大利,位置服务设置为启用,但是当我在 Chrome 上运行我的应用程序时,它总是返回“en_”。
有什么我想做的事吗?
这是 main() 中的代码:

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Locale myLocale = Localizations.localeOf(context);
return MaterialApp(
title: '',
color: Colors.red,
localizationsDelegates: [
const AppLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en', 'US'),
const Locale('it', 'IT')
// const Locale('es', 'ES'),
],
localeResolutionCallback:
(Locale locale, Iterable<Locale> supportedLocales) {
for (Locale supportedLocale in supportedLocales) {
if (kIsWeb) {
Locale webLocale = Locale(ui.window.locale.languageCode, '');
print('system locale is ${webLocale}');
return webLocale;
} else if (supportedLocale.languageCode == locale.languageCode ||
supportedLocale.countryCode == locale.countryCode) {
print('device Locale is $locale');
return supportedLocale;
}
}
return supportedLocales.first;
},
...

最佳答案

最后,主分支上的语言环境按预期工作。
更新到 Channel master,1.19.0-4.0.pre.73 解决了问题。

关于flutter - Web 应用程序的语言环境始终为 'en' Flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61666447/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com