简体   繁体   中英

Flutter: How to Recreate a Tab Bar

I have an application that has different layouts depending on user roles, users can switch between roles from settings. The app's basic layout has a tab bar, and the tab view content changes based on the tab selected. When changing the user role, I want to go to a new layout with a new tab bar having its own tab items. The problem is, when I push a new page from UserRole1 layout as below:

Navigator.pushReplacement(
     context,
     CupertinoPageRoute(builder: (context) => UserRole2Layout()),
);

the tab bar for UserRole1 layout still exists and the new layout with new tab bar is placed above it.

How can I replace the current tab bar or go to a new layout with a new tab bar?

I've found a workaround for this, basically I'm keeping a global variable to check which account type is chosen by the user. Based on which type is chosen, the app loads the tab bar while loading the app initially. When the user changes roles, I change that variable and restart the app so that the app starts anew with the new tab bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM