一款Flutter僞自定義BottomAppBar

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: <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],
    );
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章