11import 'dart:async' ;
22
33import 'package:flutter/material.dart' ;
4- import 'package:flutter_localizations/flutter_localizations.dart' ;
54import 'package:flutter_redux/flutter_redux.dart' ;
65import 'package:flutter_riverpod/flutter_riverpod.dart' ;
76import 'package:fluttertoast/fluttertoast.dart' ;
87import 'package:gsy_github_app_flutter/common/event/http_error_event.dart' ;
98import 'package:gsy_github_app_flutter/common/event/index.dart' ;
10- import 'package:gsy_github_app_flutter/common/localization/default_localizations .dart' ;
11- import 'package:gsy_github_app_flutter/common/localization/gsy_localizations_delegate .dart' ;
9+ import 'package:gsy_github_app_flutter/common/localization/extension .dart' ;
10+ import 'package:gsy_github_app_flutter/common/localization/l10n/app_localizations .dart' ;
1211import 'package:gsy_github_app_flutter/common/net/code.dart' ;
1312import 'package:gsy_github_app_flutter/model/user.dart' ;
1413import 'package:gsy_github_app_flutter/page/debug/debug_label.dart' ;
@@ -51,11 +50,11 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
5150 // Helper method to check if the locale is supported
5251 Locale _checkSupportedLocale (Locale locale) {
5352 // Define the supported locales
54- final supportedLocales = GSYLocalizations .localizedValues ;
53+ const supportedLocales = AppLocalizations .supportedLocales ;
5554
5655 // Check if the requested locale is supported
57- for (final supportedLocale in supportedLocales.keys ) {
58- if (supportedLocale == locale.languageCode) {
56+ for (final supportedLocale in supportedLocales) {
57+ if (supportedLocale.languageCode == locale.languageCode) {
5958 return locale;
6059 }
6160 }
@@ -64,8 +63,6 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
6463 return const Locale ('en' , 'US' );
6564 }
6665
67-
68-
6966 @override
7067 void initState () {
7168 super .initState ();
@@ -89,8 +86,6 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
8986 builder: (BuildContext context, WidgetRef ref, Widget ? child) {
9087 final (greyApp, appLocale, themeData) = ref.watch (appStateProvider);
9188
92-
93-
9489 // Make sure the locale is supported or fall back to a default one
9590 final effectiveLocale = _checkSupportedLocale (appLocale);
9691
@@ -104,12 +99,8 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
10499 navigatorKey: navKey,
105100
106101 ///多语言实现代理
107- localizationsDelegates: [
108- GlobalMaterialLocalizations .delegate,
109- GlobalCupertinoLocalizations .delegate,
110- GlobalWidgetsLocalizations .delegate,
111- GSYLocalizationsDelegate .delegate,
112- ],
102+ localizationsDelegates:
103+ AppLocalizations .localizationsDelegates,
113104 supportedLocales: [effectiveLocale],
114105 locale: effectiveLocale,
115106 theme: themeData,
@@ -195,31 +186,30 @@ mixin HttpErrorListener on State<FlutterReduxApp> {
195186 var context = navKey.currentContext! ;
196187 switch (code) {
197188 case Code .NETWORK_ERROR :
198- showToast (GSYLocalizations . i18n ( context) ! .network_error);
189+ showToast (context.l10n .network_error);
199190 break ;
200191 case 401 :
201- showToast (GSYLocalizations . i18n ( context) ! .network_error_401);
192+ showToast (context.l10n .network_error_401);
202193 break ;
203194 case 403 :
204- showToast (GSYLocalizations . i18n ( context) ! .network_error_403);
195+ showToast (context.l10n .network_error_403);
205196 break ;
206197 case 404 :
207- showToast (GSYLocalizations . i18n ( context) ! .network_error_404);
198+ showToast (context.l10n .network_error_404);
208199 break ;
209200 case 422 :
210- showToast (GSYLocalizations . i18n ( context) ! .network_error_422);
201+ showToast (context.l10n .network_error_422);
211202 break ;
212203 case Code .NETWORK_TIMEOUT :
213204 //超时
214- showToast (GSYLocalizations . i18n ( context) ! .network_error_timeout);
205+ showToast (context.l10n .network_error_timeout);
215206 break ;
216207 case Code .GITHUB_API_REFUSED :
217208 //Github API 异常
218- showToast (GSYLocalizations . i18n ( context) ! .github_refused);
209+ showToast (context.l10n .github_refused);
219210 break ;
220211 default :
221- showToast (
222- "${GSYLocalizations .i18n (context )!.network_error_unknown } $message " );
212+ showToast ("${context .l10n .network_error_unknown } $message " );
223213 break ;
224214 }
225215 }
0 commit comments