[英]Flutter - How to create a vertical line between two widgets
I need to create a vertical line between two widgets like this: https://imgur.com/a/22ybF6o我需要像这样在两个小部件之间创建一条垂直线: https://imgur.com/a/22ybF6o
I could do it but for a fixed size.我可以做到,但尺寸固定。 If this size changes, layout got messy like this: https://imgur.com/a/kO9NXlJ
如果这个尺寸发生变化,布局就会像这样混乱: https://imgur.com/a/kO9NXlJ
Here's my code:这是我的代码:
Widget listItem(TripsData item) {
var startDate = DateFormat('dd/MM/yy - HH:mm').format(DateTime.parse(item.start));
var endDate = DateFormat('dd/MM/yy - HH:mm').format(DateTime.parse(item.end));
return Card(
child: Stack(
children: <Widget>[
drawDestinationLine(Colors.red),
Column(
children: <Widget>[
ListTile(
leading: drawDestinationCircle('A', Colors.blue),
title: Text(startDate),
subtitle: Text(item.locationStart),
),
const Padding(padding: EdgeInsets.only(bottom: 2.0)),
ListTile(
leading: drawDestinationCircle('B', Colors.blue),
title: Text(endDate),
subtitle: Text(item.locationEnd),
),
],
),
],
),
);
}
Does someone have a solution to help me with this?有人有办法帮助我解决这个问题吗?
Let me know if need more code, but StackOverflow didn't let me put more code here..让我知道是否需要更多代码,但 StackOverflow 不允许我在此处放置更多代码。
I used the package timelines 0.1.0 which makes this easily possible我使用了 package时间线 0.1.0这使得这很容易成为可能
Check on pub.dev and the corresponding Github repo for nice examples.检查pub.dev和相应的Github 回购以获得很好的例子。
One of the sample use-cases looks like what you are looking for:示例用例之一看起来像您正在寻找的:
In this case you should use the Stack, Positioned, and ConstrainedBox widgets to create the desired arrangement. 在这种情况下,您应该使用Stack,Positioned和ConstrainedBox小部件创建所需的排列。
Something like this pseudocode, you will need to supply correct coordinates: 类似于此伪代码,您将需要提供正确的坐标:
Stack ( children: [
Positioned ( left: 0.0 , top : 0.0 , child:
ListTile (leading: drawDestinationCircle('A', Colors.blue),
title: Text(startDate),
subtitle: Text(item.locationStart),
)),
Positioned ( left: 0.0 , bottom : 0.0 , child:
ListTile (leading: drawDestinationCircle('B', Colors.blue),
title: Text(endDate),
subtitle: Text(item.locationEnd),
)),
Positioned ( left 20.0 , top : 20.0
, child: ConstrainedBox(
constraints: new BoxConstraints(
minHeight: 5.0,
minWidth: 5.0,
maxHeight: 30.0,
maxWidth: 5.0,
),
child: new DecoratedBox(
decoration: new BoxDecoration(color: Colors.red),
)
),
)
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.