Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ListTile inside horizontal ListView in Flutter?

Tags:

flutter

I am trying to use ListTiles as items of the horizontal 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 
like image 897
Leap Bun Avatar asked Nov 18 '25 23:11

Leap Bun


1 Answers

You can uses ListTile widget by wrapping it with Container or SizedBox widget.

Error Explanation:

You are getting this error because ListTiles have infinite width. If you don't give them a proper one they will surely generate such errors.

like image 128
Hamza Avatar answered Nov 20 '25 14:11

Hamza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!