flutter - 如何在 Flutter 的水平 ListView 中使用 ListTile?
问题描述
我正在尝试使用 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'),
)
],
),
);
我收到以下错误:
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
解决方案
您可以通过使用或ListTile
包装它来使用小部件Container
SizedBox widget.
错误说明:
您收到此错误是因为ListTiles
have infinite width
。如果你不给他们一个合适的,他们肯定会产生这样的错误。
推荐阅读
- php - 如何在 Debian 10.3 上启动 php7.3-fpm?错误:无法启动 PHP 7.3 FastCGI 进程管理器
- oracle - 调用时表单失败
- html - Bootstrap 社交按钮背景颜色和悬停问题
- azure-devops - Azure DevOps 2019 On-Prem - 创建集合时出错:“LeaseLostException on step Create Framework Security Namespaces”
- flutter - 如何使用 Provider 作为状态管理从列表中正确设置选定的小部件?
- c++ - 检查 gcc 4.4.7 中是否未初始化 atomic ptr(没有 nullptr)
- java - 使用 JAXB/JAX-RS 将 XML 元素包装在子元素中
- pdf - 用于使用 PDF 模板的 itext PDF 库
- reactjs - React.js:如何在多个相同的孩子之一中设置一个活动标志?
- kubernetes - 如何从基于 http 的服务器为 Kubernetes Engine 在 Google Cloud 中创建 https 端点?