Flutter_学习记录_AppBar中取消leading的占位展示

  • leading设置为null
  • automaticallyImplyLeading设置为false

看看automaticallyImplyLeading的说明:

Controls whether we should try to imply the leading widget if null.

If true and [AppBar.leading] is null, automatically try to deduce what the leading widget should be. If false and [AppBar.leading] is null, leading space is given to [AppBar.title]. If leading widget is not null, this parameter has no effect.

意思就是说:

  • 如果leading为null 并且 automaticallyImplyLeading为true , 那么会保留leading的占位位置;
  • 如果如果leading为null 并且automaticallyImplyLeading为false , 那么会将leading的位置让给title;
  • 如果leading不为null , automaticallyImplyLeading这个设置失效。

代码如下:

dart 复制代码
@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
      	
        leading: null,
        automaticallyImplyLeading: false,
        title: Container(
            margin: EdgeInsets.fromLTRB(0, 0, 0, 0), 
            height: Screenadapter.height(100),
            width:  Screenadapter.width(880) ,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(20),
              color: Color.fromARGB(10, 0, 0, 0)
            ),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Padding(padding: EdgeInsets.fromLTRB(10, 0, 0, 0), child: Icon(Icons.search, color: Colors.black26)),
                Expanded(child: Text("耳机", style: TextStyle(color: Colors.black45, fontSize: Screenadapter.fontSize(36)))),
                Padding(padding: EdgeInsets.fromLTRB(0, 0, 10, 0), child: Icon(FangXMIcon.saomiao, color: Colors.black26)),
              ],
            ),
          ),
        centerTitle: true,
        actions: [
          Container(
            padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
            width: Screenadapter.width(124),
            height: Screenadapter.height(100),
            child: InkWell(
              child: Icon(FangXMIcon.xiaoxi, color: Colors.black54 ),
            ),
          )
        ],
      ),
      body: const Center(
        child: Text(
          'GiveView is working',
          style: TextStyle(fontSize: 20),
        ),
      ),
    );
  }

效果如下:

相关推荐
程序员老刘14 小时前
跨平台开发地图:四月风暴前夕,你该怎么选?| 2026年4月
flutter·ai编程·客户端
MakeZero14 小时前
Flutter那些事-PageView
flutter
Lanren的编程日记17 小时前
Flutter鸿蒙应用开发:数据加密功能实现实战,全方位保护用户隐私数据
flutter·华为·harmonyos
梦想不只是梦与想18 小时前
flutter 与 Android iOS 通信?以及实现原理(一)
android·flutter·ios·methodchannel·eventchannel·basicmessage
2601_9495936520 小时前
Flutter OpenHarmony 三方库 path_provider 文件路径获取适配详解
flutter
哈撒Ki20 小时前
快速入门 Dart 语言
前端·flutter·dart
小蜜蜂嗡嗡20 小时前
flutter 自定义走马灯,内部为Widget控件的走马灯效果二:横向无限匀速滚动+每个Item与屏幕左侧对齐时,停靠3秒再继续滚动
开发语言·flutter
浮芷.21 小时前
生命科学数据视界防御:基于鸿蒙Flutter陀螺仪云台与三维体积光栅的视轴锁定架构
flutter·华为·架构·开源·harmonyos·鸿蒙
千码君201621 小时前
Flutter:在win10上第一次安装和尝试开发记录
flutter·gradle·android-studio·安卓模拟器
浮芷.21 小时前
微观搜打撤:基于鸿蒙flutter的内存快照算法的局内外状态隔离与高阶背包系统设计
算法·flutter·华为·开源·harmonyos·鸿蒙