我正在尝试创建动态水平列表视图。但是,当我创建列表视图时,它将占据页面上的剩余垂直空间。我尝试使用容器来限制高度,但没有成功。到目前为止,这是我尝试过的:
列出图块...
class CardTile extends StatelessWidget {
final GreetingCard greetingCard;
const CardTile({Key key, this.greetingCard}) : super(key: key);
@override
Widget build(BuildContext context) {
return
Container(
height: 150.0,
width: 80.0,
child: Card(
child: ListTile(
title: Center(child: Text(greetingCard.ocassion)),
),
),
);
}
}
列表视图生成器:
class CardList extends StatefulWidget {
@override
_CardListState createState() => _CardListState();
}
class _CardListState extends State<CardList> {
@override
Widget build(BuildContext context) {
final greetingsCards = Provider.of<List<GreetingCard>>(context);
return ListView.builder(
itemCount: greetingsCards.length,
itemBuilder: (context, index){
return Card(
child: CardTile(greetingCard: greetingsCards[index],));
}, scrollDirection: Axis.horizontal);
}
}
如何将高度限制为150像素?
答案 0 :(得分:1)
您需要限制ListView.builder的高度:
Container(
height: 150.0,
child: ListView.builder(
...
),
)