Flutter隐藏导航栏

把 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(
          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隐藏导航栏)