【发布时间】:2020-08-28 21:50:34
【问题描述】:
像标题一样,我试图在 ListView 中放置一些元素,并具有一定的高度和宽度(动态获取),所以我不想硬编码 ListView 的尺寸。
是否有任何方法可以将ListView 的高度设置为其子项的高度?
class HomepageScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
body: SafeArea(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(22),
child: Column(
children: <Widget>[
// OTHER WIDGETS
],
),
),
Container(
height: 80,
child: ListView.builder(
itemCount: rectangles.length,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
CustomRectangle rectangle = rectangles[index];
return GestureDetector(
onTap: () => print('detailed'),
child: Container(
margin: EdgeInsets.symmetric(horizontal: 20),
child: RectangleWidget(
color: rectangle.color,
height: rectangle.height,
width: rectangle.width,
title: rectangle.title,
subtitle: rectangle.subtitle,
),
),
);
},
),
)
],
),
),
);
}
}
提前致谢:)
【问题讨论】: