我使用buttomNavigationBar创建了一个这样的应用程序,以使buttomNavigationBar出现在移动到另一页面时,此代码在layout.dart上
const headers: HttpHeaders = new HttpHeaders({
'Authorization': `Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXX`
});
const bodyData = this.getBodyData(); // get whatever we want to send as body
let params: HttpParams = new HttpParams();
params = params.set('notes', 'Some notes to send');
this.httpService.post<any>(url, bodyData, headers, params);
因此,在“帐户”页面中,我有一个按钮,如果单击该按钮将显示注册页面,并且我需要隐藏bottomNavigationBar,我已经尝试过这种方法
在main.dart
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: onWillPop, // prevent click back on device
child: new Scaffold(
backgroundColor: background(),
body: Stack(
children: List<Widget>.generate(4, (int index) {
return IgnorePointer(
ignoring: index != _pageIndex,
child: Opacity(
opacity: _pageIndex == index ? 1.0 : 0.0,
child: Navigator(
onGenerateRoute: (RouteSettings settings) {
return new MaterialPageRoute(
builder: (_) => _page(index),
settings: settings,
);
},
),
),
);
}),
),
bottomNavigationBar: _bottomNavigationBar() // my navigation bar
)
);
}
Widget _page(int index) { // get index from navigation bar
switch (index) {
case 0: return Home();
case 1: return Store();
case 2: return Message();
case 3: return Account();
}
throw toast('Invalid index $index');
}
然后我在按下按钮时这样称呼它,但是它不起作用
routes: <String, WidgetBuilder>{
'/register': (context) => new Register(),
},
如何解决这个问题?非常感谢您的帮助
答案 0 :(得分:0)
将支架移动到树的下方,使其出现在每个页面中,即主页,商店等。
答案 1 :(得分:0)
bool _showBottomNavigation;
处定义一个变量。build
方法中更改其值;如果小部件是有状态的,请使用initState
。Widget build(BuildContext context) {
bool _showBottomNavigation = true;
...
}
bottomNavigationBar: _showBottomNavigation ? _bottomNavigationBar() : Container()
_showBottomNavigation = false;
Navigator.pushNamed(context, '/register');