How to change the initial page?

When my app first load, I set default page to /a, like
initialRoute: ‘/a’

There is sync call, when it returns, it could tell the app to change to a different default page, like ‘/b’

Even I rebuild the MaterialApp, the initalRoute doesn’t change since it is a Stateful Widget. I want to use Navigator.pushNamedAndRemoveUntil, but I cannot get the right context to do it since the code is in the main.dart

If I am understanding right, then the usecase for this would be to check if the user is logged In and then load the right page appropriately. In this case you could have a checkLoggedIn function call inside the initStatemethod, store the returned value in a boolean variable and check this value while building the widget and load the right page appropriately. This will work well if you are checking a value from sharedPreferences.

Could you share your code snippet, I think it will be more clear to understand what you mean.

1 Like