'horizontal listview builder in flutter for api

how to create a horizontal listview in which data is taken from dart object classes i.e API

this is the code:

return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("practice"),
        ),
        // child: Text("data")
        body:Container(
           child: ListView.builder(
           scrollDirection: Axis.horizontal,
           itemCount: l1.length,
           itemBuilder: (context , index){
              return ListTile(
                     title: Image.network(l1[index]),
                     subtitle: Text(l2[index]),
               );

i am getting this error:

RenderBox was not laid out: RenderPointerListener#784b4 relayoutBoundary=up8 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1694 pos 12: 'hasSize'


Solution 1:[1]

Your list view should be wrapped inside a container that has a height, adding height to your container may fix this

body:Container(
       height: 100,
       child: ListView.builder(
       scrollDirection: Axis.horizontal,
       //Rest of your code

Solution 2:[2]

Solved for me . your ListTile need width size . see example and change your code.

example code:

   body: ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: [1,2,3].length,
        itemBuilder: (context, index) {
          return SizedBox(
            height: 200, 
            width: 500, // <---- mandatory size
            child: ListTile(
              subtitle: Text("${[index]}"),
            ),
          );
        })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vilsad P P
Solution 2 Esmaeil Ahmadipour