小编Div*_*cak的帖子

Flutter Navigator:断言失败...!_debugLocked 在 Navigator.pushNamed() 上不正确

好吧,假设我有四个屏幕:主屏幕、登录屏幕、主页屏幕和项目屏幕。我想要的“用户流程”是:主 -> 登录(登录设置为初始路由) -> 主页 -> 项目。我可以轻松进入主屏幕,但随后收到此消息:我Another exception was thrown: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 4112 pos 12: '!_debugLocked': is not true.找到了很多解决方案,但没有一个有效。最终得到这些代码:

  1. 主要的
return MaterialApp(
  title: 'LetBike',
  theme: ThemeData(
    textTheme:
        GoogleFonts.josefinSansTextTheme(Theme.of(context).textTheme),
    primarySwatch: Colors.blue,
    visualDensity: VisualDensity.adaptivePlatformDensity,
  ),
  initialRoute: "/",
  routes: {
    "/": (context) => LoginScreen(),
    "ForgotPassword": (context) => ForgotPassword(),
    "CreateNewAccount": (context) => CreateNewAccount(),
    HomePage.routeName: (context) => HomePage(),
    ItemPage.routeName: (context) => ItemPage()
  },
);
}
Run Code Online (Sandbox Code Playgroud)
  1. 登录
Navigator.of(context).pushReplacementNamed(
HomePage.routeName,
arguments: snapshot.data);
Run Code Online (Sandbox Code Playgroud)
Navigator.of(context)
.pushNamed(ItemPage.routeName, arguments: item);
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

dart flutter stack-navigator

0
推荐指数
1
解决办法
3905
查看次数

标签 统计

dart ×1

flutter ×1

stack-navigator ×1