https://github.com/yumi0629/FlutterUI/tree/master/lib/bottomappbar
使用Flutter原生的FloatingActionButton
+BottomAppBar
實現,配合Scaffold
使用更舒服,適合不喜歡自己用Widget組合自定義BottomAppBar的小夥伴。
實現思路爲:1、自定義floatingActionButtonLocation
控制FloatingActionButton
的位置;2、自定義BottomAppBar
的shape
屬性,繪製BottomAppBar
的邊框。
使用方式如下,其中_CenterDockedFloatingActionButtonLocation
和shape: CircularRaisedRectangle(),
爲自定義部分,詳細代碼戳上面的Github鏈接:
@override
Widget build(BuildContext context) {
return new Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: _openNewPage,
elevation: 0,
child: Icon(
Icons.add,
color: Colors.white,
)),
floatingActionButtonLocation:
// 請一定要加const,否則每次點擊bottomNavigationBar,floatingActionButton會重建
const _CenterDockedFloatingActionButtonLocation(offset),
//和底欄進行融合
bottomNavigationBar: BottomAppBar(
notchMargin: 6,
color: Colors.white, //底部工具欄的顏色。
shape: CircularRaisedRectangle(),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
_buildBottomItem(_index, 0, Icons.home, "首頁"),
_buildBottomItem(_index, 1, Icons.library_music, "發現"),
_buildBottomItem(_index, -1, null, ""),
_buildBottomItem(_index, 2, Icons.email, "消息"),
_buildBottomItem(_index, 3, Icons.person, "我的"),
],
),
),
body: _viewList[_index],
);