flutter 隐藏导航栏appBar

当有的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,
       ),
    );
  }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容