我正在研究聊天应用程序的界面 . 我尝试使用以下容器自定义聊天消息,以在每条消息旁边显示一条垂直线,就像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)
],
),
)
问题是,这个:
new Container(宽度:2.0,高度:10.0,颜色:Colors.amber,子:null)
当我指定一个显式高度时,如上面的10.0,它不会随消息缩放,它只是保持在顶部,如下所示:
所以我想知道是否有一种方法可以动态地扩展行(容器)的高度,因为消息Text的另一个容器的高度增加 .
2 回答
虽然Darky的答案是正确的,但在您的情况下,您不需要知道容器尺寸 . 更简单的方法是在容器的右侧放置一个边框 .
例如:
LayoutBuilder
就是你想要的 .构建器委托接收BoxConstraint作为参数,对应于容器的大小 .