flutter - Flutter Navigator:断言失败... !_debugLocked 在 Navigator.pushNamed() 上不正确
问题描述
好吧,假设我有四个屏幕,Main、Login、Home 和 Item。我想要的“用户流程”是:Main -> Login(登录设置为initialRoute)-> Home -> Item。我可以轻松进入主屏幕,但随后我收到以下消息:Another exception was thrown: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 4112 pos 12: '!_debugLocked': is not true.
我找到了很多解决方案,但没有一个有效。结束了这些代码:
- 主要的
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()
},
);
}
- 登录
Navigator.of(context).pushReplacementNamed(
HomePage.routeName,
arguments: snapshot.data);
- 家
Navigator.of(context)
.pushNamed(ItemPage.routeName, arguments: item);
有任何想法吗?
解决方案
What if you use
"WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).popAndPushNamed(_routeName);"
instead of "Navigator.of(context).pushReplacementNamed(_routeName)"
推荐阅读
- regex - 可以使用 Angular 8 在 ngx-translate i18n json 文件中使用正则表达式吗?
- python-3.x - 如何在一行上打印多行
- c# - 将 JSON 转换为涉及大量嵌套 JSON 对象的 C#
- python - Python:更新类函数内嵌套字典的值
- string - 如何在 Clojure 中替换字符串中的特定字符?
- google-cloud-platform - 云功能无法移动存档桶中的文件
- javascript - Javascript:函数返回 0 而不是出现奇数次的数字
- php - 在 Dokan 供应商商店页面中使用 Woof 显示产品过滤器
- python - 使用numpy内存映射python提取文件
- curl - 我应该如何为 ftp 下载设置 curl 超时?