简体   繁体   English

当我们导航到新屏幕时,在 Flutter 底部导航栏应该消失

[英]In Flutter bottom navigation bar should disappear when we navigate to new screen

大家好,假设底部导航栏中有三个页面 A、B、c,当按下它时,A 中有一个按钮导航到屏幕 D 我仍然可以在这里看到底部导航栏,请帮我解决这个 P

我有同样的问题,我发现rootNavigator:true解决了它

Navigator.of(context,rootNavigator: true).push(...);

Make your screen D as StatefulWidget.使您的屏幕 D 成为 StatefulWidget。 For example:例如:

class ScreenD extends StatefulWidget {
  @override
  State createState() => new ScreenDState();
}

class ScreenDState extends State<ScreenD> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold();
  }
}

Mark your screen A as StatefulWidget too same with screen D. Then a button in screen A onPressed handler housed in BottomNavigationBar:将屏幕 A 标记为与屏幕 D 相同的 StatefulWidget。然后屏幕 A 中的按钮 onPressed 处理程序位于底部导航栏中:

Navigator.push(context, MaterialPageRoute(builder: (context) => ScreenD()),);

It should remove the BottomNavigationBar when screen D renders.当屏幕 D 呈现时,它应该删除 BottomNavigationBar。

Like @Skander answer, using RootNavigator on the "of" method should do the trick.就像@Skander 的回答一样,在“of”方法上使用 RootNavigator 应该可以解决问题。

Navigator.of(context, rootNavigator: true).push(...);

Here is the description of rootNavigator option, according to documentation:根据文档,这是 rootNavigator 选项的描述:

If rootNavigator is set to true, the state from the furthest instance of this class is given instead.如果 rootNavigator 设置为 true,则改为给出距离该类最远实例的状态。 Useful for pushing contents above all subsequent instances of Navigator.用于将内容推送到 Navigator 的所有后续实例之上。

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

相关问题 Flutter:如何在永久底部导航栏中导航到新屏幕 package - Flutter: How can I Navigate to new screen in Persistent Bottom Navigation Bar package 如何使用底部导航栏导航到特定屏幕 - How can you navigate to a specific screen in flutter with the bottom navigation bar 如何使用 flutter 中的底部导航栏导航到几个新页面? - How can i navigate to several new pages using the bottom navigation bar in flutter? 底部导航栏隐藏屏幕 - Flutter - Bottom Navigation Bar hides the screen - Flutter 如何使用 Animation 底部导航栏导航 flutter - How to navigate using Animation Bottom Navigation Bar flutter 使用底部导航器图标和页面中的图标导航到新屏幕:Flutter - Using bottom navigator icons and icons in page to navigate to a new screen: Flutter 导航到 Flutter 中的新屏幕 - Navigate to a new screen in Flutter 在flutter中如何使底部导航栏在访问前不加载屏幕 - How to make bottom navigation bar not to load the screen before visiting in flutter Flutter 如何将相同的底部导航栏显示到子屏幕 - Flutter how to show the same bottom navigation bar to a sub screen 如何通过传递选定的索引在 flutter 底部导航栏上打开屏幕 - How to open a screen on flutter bottom navigation bar by passing selected index
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM