ListView.builder
或ListView
中的Row
的mainAxisSize
属性不起作用。
return ListView.builder(
itemCount: 5,
shrinkWrap: true,
itemBuilder: (context, index) {
return Container(
color: Colors.grey,
margin: const EdgeInsets.all(2),
child: Row(
mainAxisSize: MainAxisSize.min, // not working
children: [
Text(index.toString()),
],
),
);
},
);
我期望MainAxisSize.min
属性能够缩短Row
,但是它没有。
2条答案
按热度按时间yrefmtwq1#
ListView
总是使children
覆盖父宽度。因此,根据您的要求,您可以删除Row
上的Container
,并使用Text
Package 相同的Container
,如下所示。oxf4rvwz2#