颤振如何使用导航删除底部导航 [英] Flutter how to remove bottom navigation with navigation
本文介绍了颤振如何使用导航删除底部导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除所有堆积的路线,然后返回到身份验证"页面. 我的主页就是这样.
I want to remove all stacked routes and go back to the Auth page. My home page is like this.
class _HomeScreenState extends State<HomeScreen> {
final List<StatelessWidget> pages = [
new Page1(),
new Page2(),
new Page3(),
new Page3(),
];
@override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: () async {
await Future<bool>.value(true);
},
child: new CupertinoTabScaffold(
tabBar: new CupertinoTabBar(
activeColor: Colors.blue,
inactiveColor: Colors.grey,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.looks_one),
title: Text('Page1'),
),
BottomNavigationBarItem(
icon: Icon(Icons.looks_two),
title: Text('Page2'),
),
BottomNavigationBarItem(
icon: Icon(Icons.looks_3),
title: Text('Page3'),
),
BottomNavigationBarItem(
icon: Icon(Icons.looks_4),
title: Text('Page4'),
),
],
),
tabBuilder: (BuildContext context, int index) {
return new DefaultTextStyle(
style: const TextStyle(
fontFamily: '.SF UI Text',
fontSize: 17.0,
color: CupertinoColors.black,
),
child: new CupertinoTabView(
builder: (BuildContext context) {
return pages[index];
},
),
);
},
),
);
}
}
并且我想在用户注销时删除CupertinoTabBar
.我这样尝试过.
And I want to remove CupertinoTabBar
when user logout. I tried like this.
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context) => new AtuhScreen()));
它已正确显示在屏幕上,但底部导航仍然可见.
如何正确删除底部导航?
It went to the screen correctly but bottom navigation is still visible.
How can I remove bottom navigation correctly?
推荐答案
代码
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context) => new AtuhScreen()));
将通过以下方式修复:
Navigator.of(context, rootNavigator: true).pushReplacement(MaterialPageRoute(builder: (context) => new AtuhScreen()));
rootNavigator: true
将获得最高的根窗口小部件Scaffold
或MaterialApp
,并避免显示BottomNavigationBar
.
The rootNavigator: true
will get the highest root widget Scaffold
or MaterialApp
and avoid displaying the BottomNavigationBar
.
这篇关于颤振如何使用导航删除底部导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文