Skip to content

Commit 9844f84

Browse files
committed
update entry
1 parent 9eca101 commit 9844f84

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/app.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FlutterReduxApp extends StatefulWidget {
2929
}
3030

3131
class _FlutterReduxAppState extends State<FlutterReduxApp>
32-
with HttpErrorListener {
32+
with HttpErrorListener, NavigatorObserver {
3333
/// 创建Store,引用 GSYState 中的 appReducer 实现 Reducer 方法
3434
/// initialState 初始化 State
3535
final store = new Store<GSYState>(
@@ -46,6 +46,19 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
4646
locale: Locale('zh', 'CH')),
4747
);
4848

49+
@override
50+
void initState() {
51+
super.initState();
52+
Future.delayed(Duration(seconds: 0), () {
53+
/// 通过 with NavigatorObserver ,在这里可以获取可以往上获取到
54+
/// MaterialApp 和 StoreProvider 的 context
55+
/// 还可以获取到 navigator;
56+
/// 比如在这里增加一个监听,如果 token 失效就退回登陆页。
57+
navigator.context;
58+
navigator;
59+
});
60+
}
61+
4962
@override
5063
Widget build(BuildContext context) {
5164
/// 使用 flutter_redux 做全局状态共享
@@ -66,6 +79,7 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
6679
supportedLocales: [store.state.locale],
6780
locale: store.state.locale,
6881
theme: store.state.themeData,
82+
navigatorObservers: [this],
6983

7084
///命名式路由
7185
/// "/" 和 MaterialApp 的 home 参数一个效果

0 commit comments

Comments
 (0)