如何在颤振中获得容器的高度和宽度等约束

时间:2017-10-18 20:27:55

标签: dart flutter

我目前正在研究聊天应用程序的界面。我尝试使用以下容器自定义聊天消息,以在每条消息旁边显示一条垂直线,如Snapchat确实:

child: new Container(
    margin: const EdgeInsets.symmetric(vertical: 10.0),
    child: new Row(
      mainAxisAlignment: MainAxisAlignment.end,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        new Container(
          alignment: Alignment.centerRight,
          width: 300.0,
          child: new Text(text),
        ),
        new Container(width: 2.0, height: 10.0, color: Colors.amber, child: null)
      ],
    ),
  )

问题是,这个:

  

新容器(宽度:2.0,高度:10.0,颜色:Colors.amber,子:null)

当我指定一个显式高度时,如上面的10.0,它不会与消息一起缩放,它只是像这样保持在顶部:

Short Vertical Line

所以我想知道是否有办法动态扩展行(容器)的高度,因为消息Text的另一个容器的高度增加。

2 个答案:

答案 0 :(得分:4)

虽然Darky的答案是正确的,但在您的情况下,您不需要知道容器尺寸。一种更简单的方法是在容器的右侧放置一个 border

例如:

$ ionic start angularfire2test tabs
$ npm install angularfire2 firebase --save

答案 1 :(得分:1)

LayoutBuilder就是你想要的。

构建器委托接收BoxConstraint作为参数,对应于容器的大小。

相关问题