把 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,
),
);
}
![](https://img.haomeiwen.com/i10317259/262919ab093a0d57.png)
网友评论