Flutter Routing
It's hard to tell what's going on here.
Adding "/main"
to the list of named routes should not cause any problems because routes
is just contains WidgetBuilder
s, that means Main
constructor is not called until you push "/main"
and there should be no initialization issues. Not sure what causes your issue, an error message would help.
It might be a good idea to remove the slashes from your named routes, because a slash implies that there is a route named "/"
that is the parent of "welcome"
, "splash"
and "main"
. I think what you actually want are three top-level routes:
<String, WidgetBuilder>{ "welcome": (_) => WelcomeScreen(), "splash": (_) => SplashScreen(), "main":(_) => Main(),}
Another issue I spotted is that you are adding /main
to the named routes list, but in the end you are pushing /home
. Maybe a typo?