我希望我的应用无需用户设置即可脱机工作,并在连接恢复时要求登录
我正在尝试的代码的摘录:
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
Connectivity().onConnectivityChanged.listen((ConnectivityResult result) =>
checkConnectivity().then((isOnline) {
if (isOnline && MyApp.store.state.user == null)
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => LoginPage()),
);
}));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {
...
但是我能得到的只是这个错误:
Unhandled Exception: Navigator operation requested with a context that does not include a Navigator.
The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.
我试图按照here的描述将Navigator
调用包装在Future.delayed
内,但是出现了相同的错误