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),
        ),
      ),
    );
  }

效果如下:

相关推荐
你听得到116 小时前
从需求到封装:手把手带你打造一个高复用、可定制的Flutter日期选择器
前端·flutter
哲科软件15 小时前
跨平台开发的抉择:Flutter vs 原生安卓(Kotlin)的优劣对比与选型建议
android·flutter·kotlin
天涯海风15 小时前
Kuikly 与 Flutter 的全面对比分析,结合技术架构、性能、开发体验等核心维度
flutter·kuikly
aiprtem16 小时前
基于Flutter的web登录设计
前端·flutter
coder_pig19 小时前
跟🤡杰哥一起学Flutter (三十四、玩转Flutter手势✋)
前端·flutter·harmonyos
程序员老刘1 天前
Android 16开发者全解读
android·flutter·客户端
Jalor1 天前
Flutter + 鸿蒙 | Flutter 跳转鸿蒙原生界面
flutter·harmonyos
吴Wu涛涛涛涛涛Tao1 天前
一步到位:用 Very Good CLI × Bloc × go_router 打好 Flutter 工程地基
flutter·ios
九丝城主1 天前
2025使用VM虚拟机安装配置Macos苹果系统下Flutter开发环境保姆级教程--中篇
服务器·flutter·macos·vmware
ITfeib1 天前
Flutter
开发语言·javascript·flutter