[英]How to use ListTile inside horizontal ListView in Flutter?
I am trying to use ListTiles as items of the horizontal ListView.我正在尝试使用 ListTiles 作为水平 ListView 的项目。
final brandsWidget = SizedBox(
height: 200,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
ListTile(
leading: Image.asset('img_1.png'),
title: Text('Product 1'),
subtitle: Text('\$5'),
),
ListTile(
leading: Image.asset('img_1.png),
title: Text('Product 2'),
subtitle: Text('\$3'),
)
],
),
);
I got the following error:我收到以下错误:
Another exception was thrown: BoxConstraints forces an infinite width.
Exception caught by rendering library.
BoxConstraints forces an infinite width.
The relevant error-causing widget was ListTile
You can uses ListTile
widget by wrapping it with Container
or SizedBox widget.
您可以通过用
Container
或SizedBox widget.
包装它来使用ListTile
小SizedBox widget.
Error Explanation:错误解释:
You are getting this error because ListTiles
have infinite width
.您收到此错误是因为
ListTiles
具有infinite width
。 If you don't give them a proper one they will surely generate such errors.如果你不给他们一个合适的,他们肯定会产生这样的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.