Flutter 颤振行元素保持居中,即使使用对齐方式,或列元素无法将其更改为行左对齐?

Flutter 颤振行元素保持居中,即使使用对齐方式,或列元素无法将其更改为行左对齐?,flutter,alignment,containers,Flutter,Alignment,Containers,我有下面的容器,在其中我调用一个函数来创建子小部件。问题是子行始终保持中心对齐。我试过两种方法 对齐:alignment.topLeft 我尝试将其进一步嵌入到列中,并尝试了crossAxisAlignment:crossAxisAlignment.start 这两种方法都无法将图元向左对齐。它将残留物保留在容器的中心部分。下面可能出错的是我的代码 Container( alignment:Alignment.topRight, margin: const EdgeInsets.from

我有下面的容器,在其中我调用一个函数来创建子小部件。问题是子行始终保持中心对齐。我试过两种方法

  • 对齐:alignment.topLeft
  • 我尝试将其进一步嵌入到列中,并尝试了crossAxisAlignment:crossAxisAlignment.start 这两种方法都无法将图元向左对齐。它将残留物保留在容器的中心部分。下面可能出错的是我的代码

    Container(
      alignment:Alignment.topRight,
      margin: const EdgeInsets.fromLTRB(10, 10, 0, 0),
      padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
      child: Column(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              buildDateTime("datetime"),
            ]
          )
        ],
      )
    ),
    
    这是屏幕截图


    我已使时钟图标向左对齐,日期居中,时间向右对齐。这就是你想要达到的目标吗

    Container(
      color: Colors.grey,
      alignment:Alignment.topRight,
      padding: const EdgeInsets.fromLTRB(20, 10, 20, 10),
      child: buildDateTime("datetime")
    );
    
    Widget buildDateTime(String plate) {
      return new Container(
        child: Container(
          color: Colors.transparent,
          child: Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Icon(Icons.access_time, size: 15.0, color: Colors.grey[100]),
              Text(
                ' 23/01/20202',
                style: new TextStyle(
                  color: Colors.grey[100],
                  fontFamily: "Bpreplay",
                  fontWeight: FontWeight.w400,
                  fontSize: 14.0,
                ),
              ),
              Text(
                ' 09:00',
                style: new TextStyle(
                  color: Colors.grey[100],
                  fontFamily: "Bpreplay",
                  fontWeight: FontWeight.w400,
                  fontSize: 14.0,
                ),
              ),
            ],
          ),
        ),
      );
    }
    
    我的结果是:


    我已使时钟图标向左对齐,日期居中,时间向右对齐。这就是你想要达到的目标吗

    Container(
      color: Colors.grey,
      alignment:Alignment.topRight,
      padding: const EdgeInsets.fromLTRB(20, 10, 20, 10),
      child: buildDateTime("datetime")
    );
    
    Widget buildDateTime(String plate) {
      return new Container(
        child: Container(
          color: Colors.transparent,
          child: Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Icon(Icons.access_time, size: 15.0, color: Colors.grey[100]),
              Text(
                ' 23/01/20202',
                style: new TextStyle(
                  color: Colors.grey[100],
                  fontFamily: "Bpreplay",
                  fontWeight: FontWeight.w400,
                  fontSize: 14.0,
                ),
              ),
              Text(
                ' 09:00',
                style: new TextStyle(
                  color: Colors.grey[100],
                  fontFamily: "Bpreplay",
                  fontWeight: FontWeight.w400,
                  fontSize: 14.0,
                ),
              ),
            ],
          ),
        ),
      );
    }
    
    我的结果是:


    我无法重现您提到的问题。对我来说,它占据了全部宽度

    试试这个

    Widget buildDateTime(String plate) {
      return Align(
        alignment: Alignment.centerLeft,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Icon(Icons.access_time, size: 15.0, color: Colors.grey),
            Text(
              ' 23/01/20202',
              style: const TextStyle(
                color: Colors.grey,
                fontFamily: "Bpreplay",
                fontWeight: FontWeight.w400,
                fontSize: 14.0,
              ),
            ),
            Text(
              ' 09:00',
              style: const TextStyle(
                color: Colors.grey,
                fontFamily: "Bpreplay",
                fontWeight: FontWeight.w400,
                fontSize: 14.0,
              ),
            ),
          ],
        ),
      );
    }
    

    我无法复制你提到的问题。对我来说,它占据了全部宽度

    试试这个

    Widget buildDateTime(String plate) {
      return Align(
        alignment: Alignment.centerLeft,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Icon(Icons.access_time, size: 15.0, color: Colors.grey),
            Text(
              ' 23/01/20202',
              style: const TextStyle(
                color: Colors.grey,
                fontFamily: "Bpreplay",
                fontWeight: FontWeight.w400,
                fontSize: 14.0,
              ),
            ),
            Text(
              ' 09:00',
              style: const TextStyle(
                color: Colors.grey,
                fontFamily: "Bpreplay",
                fontWeight: FontWeight.w400,
                fontSize: 14.0,
              ),
            ),
          ],
        ),
      );
    }
    


    您是否尝试过
    小部件的crossAxisAligment属性?@Joãosares是的,我也尝试过,但仍然是一样的。奇怪的是,我尝试了所有选项,但它似乎根本没有移动。@新手共享屏幕截图,请确认possible@CrazyLazyCat我已经按照你的要求添加了屏幕截图?@newbie是我的答案,你在尝试什么实现?如果是,,请记住将答案标记为正确,以便其他用户将来可以看到它。您是否尝试过
    小部件的crossAxisAligment属性?@Joãosares是的,我也尝试过,但仍然是一样的。奇怪的是,我尝试了所有选项,但它似乎根本没有移动。@newbie分享屏幕截图,请确认possible@CrazyLazyCat我有根据你的要求添加了屏幕截图?@newbie是我的答案吗?你想实现什么?如果是,请记住将答案标记为正确,以便其他用户将来可以看到。是否可能是父列或父行也需要交叉对齐设置?是。它可能是从外部保存
    容器的问题
    是的,它实际上是通过其他几个容器、列、行嵌入的,所以我想我需要检查所有这些。是否应添加所有父元素交叉对齐功能?不确定。但是你可以试试。最终目标是什么。仅显示日期列表?是否可能是父列或父行也需要交叉对齐设置?是。它可能是从外部保存
    容器的问题
    是的,它实际上是通过其他几个容器、列、行嵌入的,所以我想我需要检查所有这些。是否应添加所有父元素交叉对齐功能?不确定。但是你可以试试。最终目标是什么。只是显示日期列表?不是还是一样吗?我怀疑上面的其他容器或行或列是出现问题的原因吗?@新手,就像我在上面的评论中所说的那样。你复制了我所有的代码吗?你在我的截图上看到的是你想要实现的吗?你周围的代码一定有问题。我在截图上显示的正是我的代码所做的。应用程序中没有其他内容。尝试在没有其他内容的视图中加载此代码,然后查看它的外观。@Joaa是的,我怀疑up上有什么东西导致了此问题。让我一个一个地调试它。不,还是一样吗?我怀疑上面的其他容器、行或列是出现问题的吗?@新手,就像我在上面的评论中说的那样。你复制了我所有的代码吗?你在我的截图上看到的是你想要实现的吗?你周围的代码一定有问题。我在截图上显示的正是我的代码所做的。应用程序中没有其他内容。尝试在没有其他内容的视图中加载此代码,然后查看它的外观。@Joaa是的,我怀疑up上有什么东西导致了此问题。让我逐一调试一下。