[英]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.