@@ -53,6 +53,8 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
5353 ]);
5454
5555
56+
57+
5658 @override
5759 void initState () {
5860 super .initState ();
@@ -76,7 +78,7 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
7678 ///使用 StoreBuilder 获取 store 中的 theme 、locale
7779 store.state.platformLocale = WidgetsBinding .instance.window.locale;
7880 Widget app = new MaterialApp (
79-
81+ navigatorKey : navKey,
8082 ///多语言实现代理
8183 localizationsDelegates: [
8284 GlobalMaterialLocalizations .delegate,
@@ -146,6 +148,8 @@ mixin HttpErrorListener on State<FlutterReduxApp> {
146148 ///所以如果直接用 context 是会获取不到 MaterialApp 的 Localizations 哦。
147149 late BuildContext _context;
148150
151+ GlobalKey <NavigatorState > navKey = GlobalKey ();
152+
149153 @override
150154 void initState () {
151155 super .initState ();
@@ -167,32 +171,33 @@ mixin HttpErrorListener on State<FlutterReduxApp> {
167171
168172 ///网络错误提醒
169173 errorHandleFunction (int ? code, message) {
174+ var context = navKey.currentContext! ;
170175 switch (code) {
171176 case Code .NETWORK_ERROR :
172- showToast (GSYLocalizations .i18n (_context )! .network_error);
177+ showToast (GSYLocalizations .i18n (context )! .network_error);
173178 break ;
174179 case 401 :
175- showToast (GSYLocalizations .i18n (_context )! .network_error_401);
180+ showToast (GSYLocalizations .i18n (context )! .network_error_401);
176181 break ;
177182 case 403 :
178- showToast (GSYLocalizations .i18n (_context )! .network_error_403);
183+ showToast (GSYLocalizations .i18n (context )! .network_error_403);
179184 break ;
180185 case 404 :
181- showToast (GSYLocalizations .i18n (_context )! .network_error_404);
186+ showToast (GSYLocalizations .i18n (context )! .network_error_404);
182187 break ;
183188 case 422 :
184- showToast (GSYLocalizations .i18n (_context )! .network_error_422);
189+ showToast (GSYLocalizations .i18n (context )! .network_error_422);
185190 break ;
186191 case Code .NETWORK_TIMEOUT :
187192 //超时
188- showToast (GSYLocalizations .i18n (_context )! .network_error_timeout);
193+ showToast (GSYLocalizations .i18n (context )! .network_error_timeout);
189194 break ;
190195 case Code .GITHUB_API_REFUSED :
191196 //Github API 异常
192- showToast (GSYLocalizations .i18n (_context )! .github_refused);
197+ showToast (GSYLocalizations .i18n (context )! .github_refused);
193198 break ;
194199 default :
195- showToast (GSYLocalizations .i18n (_context )! .network_error_unknown +
200+ showToast (GSYLocalizations .i18n (context )! .network_error_unknown +
196201 " " +
197202 message);
198203 break ;
0 commit comments