如何在Flutter中使小部件的大小与另一个小部件的大小相同

时间:2020-07-06 10:19:27

标签: flutter dart layout

右侧文本的长度不固定。我想使左侧的行高与文本区域的高度相同。

是否可以将小部件与其他小部件(如Android的Flutter中的RelativeLayout或ConstraintLayout)对齐?

enter image description here

我的代码:

Container(
      padding: EdgeInsets.fromLTRB(100, 0, 100, 0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            color: Color(0xFFEEEEEE),
            width: 4,
            height: 80,
            margin: EdgeInsets.only(right: 10),
          ),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  _content,
                  style: Theme.of(context).textTheme.headline4,
                ),
              ],
            ),
          )
        ],
      ),
    );

1 个答案:

答案 0 :(得分:1)

将您的行换成IntrinsicHeight并摆脱height属性

              IntrinsicHeight(
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Container(
                      color: Color(0xFFEEEEEE),
                      width: 4,
                      margin: EdgeInsets.only(right: 10),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text(
                            'a loong loong text with a lot of letters and characters',
                            style: Theme.of(context).textTheme.headline4,
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              ),