问题描述
TL; DR需要容器填充垂直空间,以便它可以充当ontap侦听器.尝试了大多数解决方案,但似乎无济于事.
TL;DR Need the container to fill the vertical space so that it can act as a ontap listener. Have tried most solutions but nothing seems to work.
所以我想做的是使我的容器在保持固定宽度的同时填满垂直空间. 第二个是我所拥有的,第三个是我想要的.这样做的目的是使容器透明并带有手势监听器.如果有人对其他解决方案有更好的主意,请随时提出建议.
So what I am trying to do is to make my container fill up the vertical space while still having a fixed width. Two first is what I have and third is what I want. The idea is to have the container transparent with a gesture ontap listener. If anyone have a better idea as for a different solution, feel free to suggest.
Widget build(BuildContext context) {
return new GestureDetector(
onHorizontalDragUpdate: _move,
onHorizontalDragEnd: _handleDragEnd,
child: new Stack(
children: <Widget>[
new Positioned.fill(
child: new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new Container(
child: new IconButton(
padding: new EdgeInsets.only(top: 16.0, bottom: 16.0, left: 24.0, right: 24.0),
icon: new Icon(Icons.warning),
color: Colors.black12,
onPressed: () {},
)
),
],
),
),
new SlideTransition(
position: new Tween<Offset>(
begin: Offset(0.0, 0.0),
end: const Offset(-0.6, 0.0),
).animate(_animation),
child: new Card(
child: new Row(
children: <Widget>[
new Container(
width: 20.0,
height: 20.0,
color: Colors.amber,
),
new Expanded(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
_getListTile(),
_ifStoplineIsToBeShown()
],
),
)
],
)
),
),
],
)
);
}
考虑到我尝试了许多不同的事情,但似乎没有任何效果,我很确定自己缺少一些东西.
I am quite sure that i have been missing something considering the fact that I have tried a lot of different things and nothing seems to work.
我还上传了带有调试绘画的图像此处.
I have also uploaded an image with the debug painting here.
PS.我知道我已经将高度设置为固定值,但这是显示容器的唯一方法.
PS. I know I have set the height to a fixed value, but this is the only way to show the container.
推荐答案
诀窍是将IntrinsicHeight
小部件和Row
与crossAxisAlignment: CrossAxisAlignment.stretch
这将强制Row的子级垂直扩展,但是Row占用的垂直空间可能最少.
This force the children of Row to expand vertically, but Row will take the least amount of vertical space possible.
Card(
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
width: 20.0,
color: Colors.amber,
),
// Expanded(...)
],
),
)
)
这篇关于使容器小部件垂直填充父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!