当有的BottomNavigationBar对应的初始页面不需要导航栏APPBar,但是需要用到appBar进行页面跳转时,可以先隐藏APPBar,在AppBar外包裹一层Offstage,具体代码如下:
//初始值
var _currentIndex = 0;
var appTitle = ['首页','病例','商城','我的'];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
child: Offstage(
offstage: _currentIndex == 3?true:false,
child: AppBar(
centerTitle:true ,
title: Text(appTitle[_currentIndex]),
// toolbarOpacity:_currentIndex==3?0:1 ,
backgroundColor: _currentIndex!= 3?
Theme.of(context).accentColor:Colors.transparent,
),
),
preferredSize:Size.fromHeight(MediaQuery.of(context).size.height * 0.07),
),
body: getCurrentPage(),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.home), title: Text(appTitle[0])),
BottomNavigationBarItem(icon: Icon(Icons.business), title: Text(appTitle[1])),
BottomNavigationBarItem(icon: Icon(Icons.local_mall), title: Text(appTitle[2])),
BottomNavigationBarItem(icon: Icon(Icons.person), title: Text(appTitle[3])),
],
currentIndex:_currentIndex,
fixedColor: Colors.deepPurple,
onTap: _clickBottermIterm,
),
);
}