拦截器中,登录信息失效,就跳登录页,可是我在dio这边拿不到context,有没有什么好的方案.
好的,谢谢,目前已经采用每个请求都把context传入的办法,除了多写点代码,目前还是没有问题.
网络不通情况下interceptor.response.onError里e.response为空拿不到options.extra怎么办
找到不需要context的方法了,看这里:https://stackoverflow.com/questions/52962112/how-to-navigate-without-context-in-flutter-app
You can set a global key for your navigation:
final GlobalKey
Pass it to MaterialApp:
new MaterialApp(
title: 'MyApp',
onGenerateRoute: generateRoute,
navigatorKey: key,
);
Push routes:
navigatorKey.currentState.pushNamed('/someRoute');
解决了吗? 求分享代码
Most helpful comment
找到不需要context的方法了,看这里:https://stackoverflow.com/questions/52962112/how-to-navigate-without-context-in-flutter-app
You can set a global key for your navigation:
final GlobalKey navigatorKey = new GlobalKey();
Pass it to MaterialApp:
new MaterialApp(
title: 'MyApp',
onGenerateRoute: generateRoute,
navigatorKey: key,
);
Push routes:
navigatorKey.currentState.pushNamed('/someRoute');