flutter底部导航栏中间按钮凸起,导航栏中间部分凹陷效果

关键代码:

Scaffold中设置floatingActionButtonLocation: FloatingActionButtonLocation.centerDockedextendBody: true

BottomAppBar中设置shape: const CircularNotchedRectangle()

dart 复制代码
Scaffold(
              extendBody: true,//body是否延伸脚手架底部,在底部导航栏的边缘添加了凹口时,确保能看到body内容
              body: _body(),
              floatingActionButton: FloatingActionButton(
                backgroundColor: Colors.transparent,
                onPressed: () {
                  isLogin().then((value) {
                    if (value == true) {
                      Utils().postDialog(context);
                    } else {
                      NavigatorUtil.push(LoginPage());
                    }
                  });
                },
                child: Image.asset(PathConfig.iconPublishGreen,width: 112.w,height: 112.w),
              ),
              floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
              bottomNavigationBar: _bottomNavigationAppBar(),
            );


//中间凸出的底部导航栏(和floatingActionButton配合使用)
  _bottomNavigationAppBar(){
    return SizedBox(
      height: 110.w,
      child: BottomAppBar(
        color: Colors.white,
        shape: const CircularNotchedRectangle(),//添加一个凹口的形状
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            // 首页底部图标
            Expanded(child: GestureDetector(
                child: _currentIndex == 0
                    ? Image.asset(PathConfig.iconLogoRound,width: 64.w,height: 64.w)
                    : Container(
                  color: Colors.transparent,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        width: 40.w,
                        height: 40.w,
                        margin: EdgeInsets.only(bottom: 4.w),
                        child: Image(
                          image: AssetImage(PathConfig.iconUnselectAtui),
                        ),
                      ),
                      Text(S.of(context).atui,
                          style: TextStyle(
                              fontSize: 20.sp,
                              color: _currentIndex == 0 ? Color(0xffe63850) : Color(0xffD2D5D4)))
                    ],
                  ),
                ),
                onTap: (){
                  _changePage(0);
                }
            )),
            // 商城底部图标
            Expanded(child: GestureDetector(
                child: Container(
                  color: Colors.transparent,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        width: 40.w,
                        height: 40.w,
                        margin: EdgeInsets.only(bottom: 4.w),
                        child: Image(
                          image: AssetImage(
                              _currentIndex == 1 ? PathConfig.iconSelectedMarket : PathConfig.iconUnselectMarket),
                        ),
                      ),
                      Text(S.of(context).market,
                          style: TextStyle(
                              fontSize: 20.sp, color: _currentIndex == 1 ? JadeColors.green_2 : Color(0xffD2D5D4)))
                    ],
                  ),
                ),
                onTap: (){
                  _changePage(1);
                }
            )),
            // 发布图标
            Expanded(child: GestureDetector(
                child: Column(
                  children: <Widget>[
                    Container(
                      width: 40.w,
                      height: 40.w,
                    ),
                    /*Text(
                      S.of(context).publish,
                      style: TextStyle(
                          fontSize: 13,
                          color: JadeColors.green_2),
                    )*/
                  ],
                ),
                onTap: (){
                  //_changePage(2);
                }
            )),
            // 消息底部图标
            Expanded(child: GestureDetector(
              child: Container(
                color: Colors.transparent,
                // alignment: Alignment.center,
                child: Stack(
                  alignment: Alignment.center,
                  children: <Widget>[
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Container(
                          width: 40.w,
                          height: 40.w,
                          margin: EdgeInsets.only(bottom: 4.w),
                          child: Image(
                            image: AssetImage(_currentIndex == 3 ? PathConfig.iconSelectedMessage : PathConfig.iconUnselectMessage),
                          ),
                        ),
                        Text(
                          S.of(context).xiaoxi,
                          style: TextStyle(
                              fontSize: 20.sp,
                              color: _currentIndex == 3 ? JadeColors.green_2 : Color(0xffD2D5D4)),
                        )
                      ],
                    ),
                    Positioned(
                        right: 40.w,
                        top: 6.w,
                        child: _messageCountView())
                  ],
                ),
              ),
              onTap: (){
                _changePage(3);
              },
            )),
            // 我的底部图标
            Expanded(child: GestureDetector(
              child: Container(
                  color: Colors.transparent,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        width: 40.w,
                        height: 40.w,
                        margin: EdgeInsets.only(bottom: 4.w),
                        child: Image(
                          image: AssetImage(_currentIndex == 4 ? PathConfig.iconSelectedMine : PathConfig.iconUnselectMine),
                        ),
                      ),
                      Text(
                        S.of(context).wode,
                        style: TextStyle(
                            fontSize: 20.sp,
                            color: _currentIndex == 4 ? JadeColors.green_2 : Color(0xffD2D5D4)),
                      )
                    ],
                  )
              ),
              onTap: (){
                _changePage(4);
              },
            ))
          ],
        ),
      ),
    );

  }
相关推荐
踏雪羽翼13 小时前
android TextView实现文字字符不同方向显示
android·自定义view·textview方向·文字方向·textview文字显示方向·文字旋转·textview文字旋转
lxysbly13 小时前
安卓玩MRP冒泡游戏:模拟器下载与使用方法
android·游戏
夏沫琅琊15 小时前
Android 各类日志全面解析(含特点、分析方法、实战案例)
android
程序员JerrySUN16 小时前
OP-TEE + YOLOv8:从“加密权重”到“内存中解密并推理”的完整实战记录
android·java·开发语言·redis·yolo·架构
2501_9462447817 小时前
Flutter & OpenHarmony OA系统设置页面组件开发指南
开发语言·javascript·flutter
TeleostNaCl17 小时前
Android | 启用 TextView 跑马灯效果的方法
android·经验分享·android runtime
TheNextByte118 小时前
Android USB文件传输无法使用?5种解决方法
android
quanyechacsdn19 小时前
Android Studio创建库文件用jitpack构建后使用implementation方式引用
android·ide·kotlin·android studio·implementation·android 库文件·使用jitpack
程序员陆业聪20 小时前
聊聊2026年Android开发会是什么样
android
编程大师哥20 小时前
Android分层
android