在开始和居中的行中排列元素

I have a dilemma that I can't seem to solve. I have an existing row in Flutter. Essentially what I want to accomplish is to have the first element(yellow) at the start of the row, and the second element(red) in the center of the element. I know Row has the mainAxisAlignment, but I need a different alignment for each each element (i.e. both MainAxisAlignment.start & MainAxisAlignment.center). Thanks for any help!

Example Picture

我能够得出的最接近的结果是:

Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        yellowElement,
        Expanded(child: redElement),
      ],
    );

但这并不是完全居中,而是在黄色占据其空间后剩余的可用空间中居中。

评论
  • 咕噜咕噜
    咕噜咕噜 回复

    几周前我遇到了这个问题,我发现的唯一解决方案是Stack ...像这样

            Stack(
              children: <Widget>[
                Container(
                  color: Colors.grey,
                  width: 250,
                  height: 50,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: <Widget>[
                      Container(width: 50, color: Colors.red),
                    ],
                  ),
                ),
                Positioned(
                  top: 0,
                  bottom: 0,
                  child: Container(
                    width: 20,
                    color: Colors.yellow,
                  ),
                )
              ],
            )
    

    enter image description here