我在一个Card
小部件中有一个ListView
小部件,该卡具有以下代码结构:
return Card(
child: Row(
// crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Image(
image: AssetImage('assets/images/my-img.jpg'),
width: 150,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, // THIS HAS NO EFFECT
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(content.title),
Text(content.description),
],
),
Row(
// crossAxisAlignment: CrossAxisAlignment.baseline,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.accessibility),
Text('cool')
],
),
Text('something else'),
],
)
],
),
),
],
),
);
我正在尝试使column
中的row
具有spaceBetween
对齐方式,因为现在column
垂直居中。我尝试将CrossAxisAlignment.stretch
添加到Row
小部件中,但出现错误:
BoxConstraints强制无限高
答案 0 :(得分:0)
Column
占据所有可用高度。考虑用固定高度Column
将Expanded
包裹在Container
内。
要使Column
占用尽可能多的空间,请设置mainAxisSize: MainAxisSize.min
。但是,所有小部件都已打包,所有Alignments
均无效。
因此,您可能正在寻找的是将height
的{{1}}设置为其Row
children
的最大高度。这可以通过用widget
将Row
包裹起来来实现。
IntrinsicHeight
答案 1 :(得分:0)
您可以在列和行之间添加一个SizedBox。
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(content.title),
Text(content.description),
],
),
//Sized Box
SizedBox(height: //whatever double),
Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.accessibility),
Text('cool')
],
),
Text('something else'),
],
)