好吧,假设我有四个屏幕:主屏幕、登录屏幕、主页屏幕和项目屏幕。我想要的“用户流程”是:主 -> 登录(登录设置为初始路由) -> 主页 -> 项目。我可以轻松进入主屏幕,但随后收到此消息:我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()
},
);
}
Run Code Online (Sandbox Code Playgroud)
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)
有任何想法吗?