How to navigate to another page on load in Flutter?

Posted by Jennifer | Updated on

Want to navigate to another page on load in Flutter? You need to either use a ternary in the onTap if you’re using the settings button or, if you just want it to automatically send the user to the correct page when the app starts, you can put the ternary in the MyApp build method.

If you are using the settings button and just want it to pop back to the previous page if the person is not logged in then you can change NotLoggedIn() to a pop.

For some strange reason SO is refusing to post the code when it is properly formatted with four spaces, exactly as it asks, so I’m just going to make a gist.

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers