Episode - 14 Navigate to Cart & Settings Page
Just we have added the conditions and appStateManager function in login and SignUp page. Let us code the condition for other screens and appStateManager
Open the CustomAppbar here we will write the appStateManager functions to navigate to Cart Screen and Settings Screen In the onPressed Function of the cart IconButton write the code
Provider.of<AppStateManager>(context, listen: false).onCartTapped(true);
Also in the setting IconButton on pressed function write the following code.
Provider.of<AppStateManager>(context, listen: false).onSettingTapped(true);
Navigate to Settings Screen here we have two button one is logout and other is MyBooksScreen. Let us first tackle the MyBookScreens. In the MyBooks onPressedFunction class the onMyBookTapped function and pass true as the value in the parameter.
Provider.of<AppStateManager>(context, listen: false).onMyBookTapped(true);
Go to cart screen and scroll to Checkout button onPressed function and add the follwing code there.
Provider.of<AppStateManager>(context, listen: false).onCheckoutTapped(true);
Now let is add the conditions for all these pages.
if (appStateManager.onCart ||
appStateManager.onCart && bookManager.selectedIndex != -1 ||
appStateManager.onCart &&
appStateManager.onReadBook &&
bookManager.selectedIndex != -1)
CartScreen.page(),
if (appStateManager.onSettings ||
appStateManager.onSettings && bookManager.selectedIndex != -1 ||
appStateManager.onSettings &&
appStateManager.onReadBook &&
bookManager.selectedIndex != -1 &&
!appStateManager.onCart)
SettingsScreen.page(),
if (appStateManager.onCheckout) CheckoutScreen.page(),
if (appStateManager.onMyBooks) MyBooksScreen.page(),
We check if the page appStateManger is true and selectedIndex is not equal to -1 cause we might go click on the detail page and that might change the selectedIndex .