如何在AppbarCenter a column?我在网上搜索过,即使添加了带有mainAxisAlignmentmainAxisSize的行,该列仍然没有处于中心位置.所有输入的RIA.此外,该页面是第二页面,因此有一个 bootstrap 图标.

enter image description here

return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Container(
          color: Colors.deepPurple,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: [
              Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.only(top: 8.0),
                    child: Text(widget.id),
                  ),
                  Padding(
                    padding: const EdgeInsets.symmetric(vertical: 8.0),
                    child: Text(
                      _caption,
                      style: const TextStyle(fontSize: 14),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );

推荐答案

您的代码按预期工作:

看看您的小部件的外观:它正确地将列置于AppBar内的中心.

enter image description here

这里有一个小例子,它位于应用程序栏内的一列中心,全部都是关于设置centerTitle: true

appBar: AppBar(
  backgroundColor: Colors.blue,
  centerTitle: true,
  title: Column(
    children: [
      Text('First Text'),
      Text('Second Text'),
      
    ],
  ),

看起来如何:

enter image description here

如果您期待不同的输出,请告诉我.


更新

现在,领先的小部件在center calculations中,我们必须从计算中忽略它,这可以通过设置一个类似的小部件来实现,该小部件分配与应用栏动作中领先的宽度相同:

  appBar: AppBar(
    title: Container(
      color: Colors.amber,
      child: Column(
        children: [
          Text('Centered Centered'),Text('Centered'),
        ],
      ),
    ),
    centerTitle: true,
    leadingWidth: 60,
    leading: GestureDetector(
      child: Icon(Icons.arrow_back),
    ) ,
    actions: [
      SizedBox(width: 60,),
    ],
  ),

它看起来是这样的,它完全以中心为中心:

enter image description here

希望对你有帮助.

Flutter相关问答推荐

Flutter:如何在盒子内创建图像带borderDecoration Radius带文本

为什么我需要等待重新访问Firestore数据库,即使它已经做了之前?

如何创建一个按钮来在Ffltter Webview中转到上一页?

如何创建这样的按钮

参数类型';List<;Dynamic&>不能分配给参数类型';List<;SingleChildWidget&>';

在创建显示此错误的Flutter 深度链接时

Flutter:无法构建iOS应用程序-找不到PigeonParser.h文件

自定义类提供程序 Riverpod Flutter 中的可变变量

使用 Flutter 和 Dio 将图像上传到 API

网页浏览器不支持鼠标滚动的行项目

围绕父组件旋转位置组件

ListView 后台可见

Flutter - 我需要显示文本,但应用程序不需要

Container 的 Flutter 背景图片不会出现

如何删除图像边框半径与其父容器边框半径之间的空白

为什么 ref.watch(otherProvider.stream) 在 Riverpod 2.x 中被弃用并且将在 3.x 中被删除?

更改文本字段Flutter 中最大字母的 colored颜色

Flutter 中的无效日期格式 2022 年 11 月 14 日

TextSpan 避免符号字符串组上的换行符

setState 不会在第一次更新 - Flutter