@@ -48,6 +48,24 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
4848
4949 NavigatorObserver navigatorObserver = NavigatorObserver ();
5050
51+ // Helper method to check if the locale is supported
52+ Locale _checkSupportedLocale (Locale locale) {
53+ // Define the supported locales
54+ final supportedLocales = GSYLocalizations .localizedValues;
55+
56+ // Check if the requested locale is supported
57+ for (final supportedLocale in supportedLocales.keys) {
58+ if (supportedLocale == locale.languageCode) {
59+ return locale;
60+ }
61+ }
62+
63+ // Fall back to English if the locale is not supported
64+ return const Locale ('en' , 'US' );
65+ }
66+
67+
68+
5169 @override
5270 void initState () {
5371 super .initState ();
@@ -71,6 +89,11 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
7189 builder: (BuildContext context, WidgetRef ref, Widget ? child) {
7290 final (greyApp, appLocale, themeData) = ref.watch (appStateProvider);
7391
92+
93+
94+ // Make sure the locale is supported or fall back to a default one
95+ final effectiveLocale = _checkSupportedLocale (appLocale);
96+
7497 /// 使用 flutter_redux 做部分状态共享
7598 /// 通过 StoreProvider 应用 store
7699 /// 这里是为了展示使用 flutter_redux 的能力所以使用了多种状态管理
@@ -87,8 +110,8 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
87110 GlobalWidgetsLocalizations .delegate,
88111 GSYLocalizationsDelegate .delegate,
89112 ],
90- supportedLocales: [appLocale ],
91- locale: appLocale ,
113+ supportedLocales: [effectiveLocale ],
114+ locale: effectiveLocale ,
92115 theme: themeData,
93116 navigatorObservers: [navigatorObserver],
94117
0 commit comments