当在 ListView 内部使用时,Card 的宽度可以用 SizedBox 控制,但高度保持无限。我想知道如何限制它。
Widget buildCard(String text) {
return SizedBox(
height: 220.0, // this does not work
width: 180.0, // this works
child: Card(
child: Column(
children: [
ListTile(
title: Text('Title: $text'),
subtitle: Text('Subtitle: $text'),
),
],
),
),
);
}
Widget build(BuildContext context) {
return MaterialApp(
// ...
home: Scaffold(
// ...
body: ListView(
children: [
buildCard('one'),
buildCard('two'),
buildCard('three'),
buildCard('four'),
buildCard('five'),
],
scrollDirection: Axis.horizontal,
),
),
);
}
演示可用at DartPad .
最佳答案
只给 ListView
height
SizedBox(
height: 220,
child: ListView(
//....
关于flutter - 无法使用 SizedBox 限制 Card 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63827395/