簡體   English   中英

如何在 Flutter 中的水平 ListView 中使用 ListTile?

[英]How to use ListTile inside horizontal ListView in Flutter?

我正在嘗試使用 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 

您可以通過用ContainerSizedBox widget.包裝它來使用ListTileSizedBox widget.

錯誤解釋:

您收到此錯誤是因為ListTiles具有infinite width 如果你不給他們一個合適的,他們肯定會產生這樣的錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM