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

效果如下:

相关推荐
木叶丸16 小时前
AI三大核心概念通俗指南:AIGC、Agent、MCP
人工智能·flutter·架构
火柴就是我21 小时前
每日见闻之Container Decoration
android·flutter
古希腊被code拿捏的神1 天前
【Flutter】面试记录
flutter·面试·职场和发展
nc_kai1 天前
Flutter 之 table_calendar 控件
flutter
0wioiw01 天前
Flutter基础(前端教程⑨-图片)
前端·flutter
Engandend2 天前
Flutter与iOS混合开发交互
flutter·ios·程序员
浅忆无痕2 天前
Flutter抓包
前端·flutter
火柴就是我2 天前
每日见闻之尝试大白话说清Flutter的事件传递
flutter
Lucifer晓2 天前
记录一次Flutter项目上传App Store Connect出现“Validation failed”错误的问题
flutter·ios
江上清风山间明月2 天前
一周掌握Flutter开发--10. 结构与设计模式
flutter·设计模式·快速