一款Flutter伪自定义BottomAppBar

一款Flutter伪自定义BottomAppBar_第1张图片

https://github.com/yumi0629/FlutterUI/tree/master/lib/bottomappbar

  使用Flutter原生的FloatingActionButton+BottomAppBar实现,配合Scaffold使用更舒服,适合不喜欢自己用Widget组合自定义BottomAppBar的小伙伴。

  实现思路为:1、自定义floatingActionButtonLocation控制FloatingActionButton的位置;2、自定义BottomAppBarshape属性,绘制BottomAppBar的边框。

  使用方式如下,其中_CenterDockedFloatingActionButtonLocationshape: 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],
    );

你可能感兴趣的:(一款Flutter伪自定义BottomAppBar)