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

效果如下:

相关推荐
行者962 小时前
Flutter与OpenHarmony深度整合:打造高性能自定义图表组件
flutter·harmonyos·鸿蒙
行者962 小时前
Flutter适配OpenHarmony:高效数据筛选组件的设计与实现
开发语言·前端·flutter·harmonyos·鸿蒙
yujunlong39193 小时前
Dart Frog 后端开发实战:轻量级 API 构建与生产环境调优
flutter·dart·dart frog
Swuagg3 小时前
Flutter 探索入门
flutter
kirk_wang3 小时前
当Flutter的并发利器遇上鸿蒙:flutter_isolate的OHOS适配之旅
flutter·移动开发·跨平台·arkts·鸿蒙
AiFlutter4 小时前
五、交互行为(01):按钮
flutter·低代码·低代码平台·aiflutter·aiflutter低代码
kirk_wang4 小时前
Flutter艺术探索-Flutter表单组件:TextField与验证处理
flutter·移动开发·flutter教程·移动开发教程
kirk_wang4 小时前
Flutter艺术探索-Flutter手势与交互:GestureDetector使用指南
flutter·移动开发·flutter教程·移动开发教程
不爱吃糖的程序媛5 小时前
Flutter-OH 三方库适配指南:核心文件+实操步骤
flutter
行者965 小时前
OpenHarmony Flutter 搜索体验优化实战:打造高性能跨平台搜索组件
flutter·harmonyos·鸿蒙