简体   繁体   English

Flutter:如何重新创建标签栏

[英]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.更改用户角色时,我想将 go 更改为新的布局,新的标签栏有自己的标签项。 The problem is, when I push a new page from UserRole1 layout as below:问题是,当我从 UserRole1 布局推送新页面时,如下所示:

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. UserRole1 布局的标签栏仍然存在,并且带有新标签栏的新布局放置在其上方。

How can I replace the current tab bar or go to a new layout with a new tab bar?如何将当前标签栏或 go 替换为具有新标签栏的新布局?

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.当用户更改角色时,我更改该变量并重新启动应用程序,以便应用程序使用新的标签栏重新启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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