Flutter Navigator 2.0

Nov 8 2022 · Dart 2.17.3, Flutter 3.0.2, Android Studio 2020.3

Part 3: Use the Navigation

13. Navigate to the Home Page

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 12. Display the Login & Sign-up Pages Next episode: 14. Navigate to the Cart & Settings Pages

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 13. Navigate to the Home Page

Episode 13 - Navigate to Home Page

We have to show the HomeScreens from two routes 1st when users SignUps for the first time we take the user to the HomeScreen and 2nd route when the user Logins that time we show the homeScreen. So First let us create these two function in the LoginIn Screen and SignUp Screen.

Navigate to LoginScreen and in the onPressed anonymous function let us call the login function that we have written in our appStateManager.

Provider.of<AppStateManager>(context, listen: false).login('Anyusername', 'anypassword'); 

Now open the BookRouterDelegate and add the following condition to navigate to HomeScreen.

if(appStateManager.isLoggedIn) HomeScreen.page(),

Reload the app and now press the login button on the login page and you will be taken to homePage.

Navigate to Sign Up Screen and in the SignUp button anonymous function let us call the onSignUpCompleted() function from our appStateManager

Provider.of<AppStateManager>(context, listen: false).onSignUpCompleted();

Reload the app and check by clicing the signup button you will notice that nothing happens that is cause we have not changed the condition that we have written in pages to display our homepage.

if (appStateManager.isLoggedIn || !appStateManager.isSignUp && appStateManager.onSignUpComplete) HomeScreen.page(),

Here We check first if our isLogged is true or we check if the onSignUpComplete is true. If any of the two conditions is true then we want to display the homePage. Now reload the App and press the SignUp button and you will notice that home page is displayed. reload the app and check if the login button works as well.