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: [
_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],
);