I am using flutter_modular to separate my app into some module, everything looks fine until I notice that each time I perform a hot reload, my application automatically jump back to login page which is also the initial one.
This is my setting:
class AppWidget extends StatelessWidget {
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: "/",
onGenerateRoute: Modular.generateRoute,
navigatorKey: navigatorKey,
);
}
}
Obviously, this issue does not happen to flutter native routing, so why does this appear in such a high voting package?
Here the link to the dependency: https://github.com/Flutterando/modular
And the link on pub.dev: https://pub.dev/packages/flutter_modular
I accidentally fixed this issue after a week of Googling desperately. I think it quite dumb that such an important config is not documented on the homepage.
class AppWidget extends StatelessWidget {
// final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: "/",
onGenerateRoute: Modular.generateRoute,
navigatorKey: Modular.navigatorKey, // Here's the culprit
);
}
}
By using flutter_modular, the user has to put the Modular.navigatorKey into MaterialApp instead of generating a new one.
I am creating this question so no one has to go through all of my sufferings again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With