我试图使用本地化来获取移动countryCode和languageCode
小部件构建(BuildContext context){ Locale myLocale = Localizations.localeOf(context); 打印(myLocale ….
使用 LocaleResolutionCallback 获取设备区域设置:
LocaleResolutionCallback
Widget build(BuildContext context) { Locale myLocale ; return MaterialApp( title: 'Title', debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), home: LoginPage(), localeResolutionCallback: (deviceLocale, supportedLocales) { myLocale = deviceLocale ; // here you make your app language similar to device language , but you should check whether the localization is supported by your app print(myLocale.countryCode); print(myLocale.languageCode); } localizationsDelegates: [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], supportedLocales: [ Locale('es' 'ES'), ], ); }