gpt4 book ai didi

flutter - 无法使用 SizedBox 限制 Card 的高度

转载 作者:行者123 更新时间:2023-12-03 03:31:05 24 4
gpt4 key购买 nike

当在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com