美文网首页
Flutter隐藏导航栏

Flutter隐藏导航栏

作者: 倪大头 | 来源:发表于2019-07-24 09:19 被阅读0次

    把 AppBar 用 Offstage 包起来

    appBar: PreferredSize(
        child: Offstage(
          offstage: _selectedIndex == 2 ? true : false,
          child: AppBar(
            title: _tabbarTitles[_selectedIndex],
          ),
        ),
        preferredSize: Size.fromHeight(MediaQuery.of(context).size.height * 0.07),
    ),
    

    完整代码:

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: PreferredSize(
          child: Offstage(
            offstage: _selectedIndex == 2 ? true : false,
            child: AppBar(
              title: _tabbarTitles[_selectedIndex],
            ),
          ),
          preferredSize: Size.fromHeight(MediaQuery.of(context).size.height * 0.07),
        ),
        body: _pages[_selectedIndex],
        bottomNavigationBar: BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: _tabbarIcons[0],
              title: _tabbarTitles[0],
            ),
            BottomNavigationBarItem(
              icon: _tabbarIcons[1],
              title: _tabbarTitles[1],
            ),
            BottomNavigationBarItem(
              icon: _tabbarIcons[2],
              title: _tabbarTitles[2],
            ),
          ],
          currentIndex: _selectedIndex,
          selectedItemColor: Colors.red,
          onTap: _onItemTapped,
        ),
      );
    }
    
    image.png

    相关文章

      网友评论

          本文标题:Flutter隐藏导航栏

          本文链接:https://www.haomeiwen.com/subject/czdtrctx.html