實現(xiàn)底部導航欄并點擊切換頁面可簡述為有三種方式
TabBar + TabBarView
BottomNavigationBar + BottomNavigationBarItem绵跷,實現(xiàn)規(guī)則的底部導航欄
自定義 BottomAppBar好爬,實現(xiàn)不規(guī)則底部導航欄
const BottomAppBar({
Key? key,
this.color,//背景色
this.elevation,//陰影效果
this.shape,//設(shè)置底欄的形狀淆储,一般使用這個都是為了和floatingActionButton融合檐薯,所以使用的值都是CircularNotchedRectangle(),有缺口的圓形矩形
this.clipBehavior = Clip.none,
this.notchMargin = 4.0,//FloatingActionButton和BottomAppBar之間的距離逛万。
this.child,
})
bottomNavigationBar: BottomAppBar(
//設(shè)置底欄的形狀恋拷,一般使用這個都是為了和floatingActionButton融合洽蛀,
//所以使用的值都是CircularNotchedRectangle(),有缺口的圓形矩形演顾。
shape: CircularNotchedRectangle(),
color: Colors.white,
child: Container(
height: 49,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 1,
child: InkWell(
child: Image.asset(
index == 0 ? "images/custome_icon_home_select.png" : "images/custome_icon_home.png",
width: 42,
height: 42,
),
onTap: () {
if (index != 0) {
setState(() {
index = 0;
});
}
},
),
),
Expanded(
flex: 1,
child: Container(),
),
Expanded(
flex: 1,
child: InkWell(
child: Image.asset(
index == 1 ? "images/custome_icon_gerenzhongxin_select.png" : "images/custome_icon_gerenzhongxin.png",
width: 42,
height: 42,
),
onTap: () {
if (index != 1) {
setState(() {
index = 1;
});
}
},
),
),
],
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: MyFloatingActionButton(),