How to make a widget's size same as another widget in Flutter

白昼怎懂夜的黑 提交于 2021-01-29 08:43:35

问题


The length of the texts on right is not fixed. I want to make the height of the line on left same as the texts area height.

Is there a way to align a widget to another widget like Android's RelativeLayout or ConstraintLayout in Flutter?

my code:

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:


Wrap your row into IntrinsicHeight and get rid of the height property

              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,
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              ),


来源:https://stackoverflow.com/questions/62753966/how-to-make-a-widgets-size-same-as-another-widget-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!