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

效果如下:

相关推荐
爱吃大芒果1 小时前
GitCode口袋工具的部署运行教程
flutter·华为·harmonyos·gitcode
爱吃大芒果1 小时前
Flutter基础入门与核心能力构建——Widget、State与BuildContext核心解析
flutter·华为·harmonyos
灵感菇_4 小时前
Flutter Riverpod 完整教程:从入门到实战
前端·flutter·ui·状态管理
Zender Han5 小时前
Flutter Gradients 全面指南:原理、类型与实战使用
android·flutter·ios
火柴就是我5 小时前
Flutter Path.computeMetrics() 的使用注意点
android·flutter
等你等了那么久6 小时前
Flutter打包APK记录
flutter·dart
小a彤8 小时前
Flutter 与 Dart 语言的核心特性与应用
flutter
小a彤9 小时前
Flutter UI 美化与适配技巧详解
flutter·ui
5008410 小时前
鸿蒙 Flutter 原子化服务进阶:轻量应用开发、跨设备流转与上架适配
java·flutter·华为·性能优化
kirk_wang10 小时前
Flutter插件跨平台适配技术分析之是否需要适配鸿蒙端-screenshot
flutter·华为·harmonyos