代码之家  ›  专栏  ›  技术社区  ›  Mathieu

颤振嵌套行主轴对准

  •  0
  • Mathieu  · 技术社区  · 5 年前

    我想这样做:

    website display

    但我得到的是:

    mobile display

    这是我的代码:

    Row itemTransaction(BuildContext context, Transaction transaction) {
      /// This is the function that will build each item of our transaction list.
      return new Row(
        children: <Widget>[
          new Container(
            width: MediaQuery.of(context).size.width / 6,
            height: MediaQuery.of(context).size.width / 6,
            child: new Image.asset(
              (transaction.sent) ? "images/tx_output.png" : "images/tx_input.png",
            ),
          ),
          new Column(
            children: <Widget>[
              new Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  discoderyText("test"),
                  discoderyText("test 2"),
                ],
              ),
              discoderyText("SOME HASH KEY"),
            ],
          ),
        ],
      );
    }
    

    这个 discoderyText 基本上是自定义文本(即带有颜色)。

    如你所见,有 mainAxisAlignment: MainAxisAlignment.spaceBetween 准备好了,所以 test test2 应该 打开 对边 .

    当我移除图像并且只返回一个 Row 包含两个 Text ,然后我设置 mainAxisAlignment ,它起作用了。好像 嵌套行不能使用此变量 .

    以下是我的基本观点:

    Layout plan

    0 回复  |  直到 5 年前
        1
  •  1
  •   CopsOnRoad    5 年前

    截图

    enter image description here

    Row(
      children: <Widget>[
        Container(
          width: MediaQuery.of(context).size.width / 6,
          height: MediaQuery.of(context).size.width / 6,
          child: CircleAvatar(backgroundImage: AssetImage(chocolateImage),),
        ),
        Expanded( // add this
          child: Padding(
            padding: const EdgeInsets.all(8.0), // give some padding
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min, // set it to min
              children: <Widget>[
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Text("test"),
                    Text("test 2"),
                  ],
                ),
                Text("SOME HASH KEY HERE"),
              ],
            ),
          ),
        ),
      ],
    )