Well, let's say I have four screens, Main, Login, Home and Item. My desired "user-flow" is: Main -> Login (login is set as initialRoute) -> Home -> Item. I can get to the Home screen easily, but then I get this message: Another exception was thrown: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 4112 pos 12: '!_debugLocked': is not true.
I have found a looot of solutions, but none of them worked. Ended up with these codes:
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);
Any ideas?
What if you use
"WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).popAndPushNamed(_routeName);"
instead of "Navigator.of(context).pushReplacementNamed(_routeName)"