Emmanuel Okocha
Emmanuel Okocha

Reputation: 397

constraints.hasBoundedHeight': is not true flutter

I am stacking widgets and i want it to be scrollable so i used a listview and i am getting this error (constraints.hasBoundedHeight': is not true flutter) i saw somewhere that listview cannot be placed inside a listview so i changed it to Column but i still got the same error. Below is my Code. Thanks.

ListView homeList(){
var listView = ListView(
  shrinkWrap: true,
  children: <Widget>[
    _imageSlider(),

    Padding(
      padding: EdgeInsets.only(top: 15.0, bottom: 15.0, left: 15.0),
      child: Text("Trending", style: TextStyle(color: Colors.white, fontSize: 15.0),),
    ),

   Container(
     child: FutureBuilder(
       future: _trendingListImages(),
         builder: (BuildContext context, AsyncSnapshot async){
           if(async.data == null){
           return ColorLoader3(
          radius: 20.0,
          dotRadius: 5.0,
           );
          }else{
            return ListView.builder(
                shrinkWrap: true,
                scrollDirection: Axis.horizontal,
                itemCount: async.data.length,
                itemBuilder: (BuildContext context, int position) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Card(
                        elevation: 18.0,
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.all(Radius.circular(10.0))),
                        child: Image.network(
                          "http://image.tmdb.org/t/p/w500/"+async.data[position].backdropPath,
                          fit: BoxFit.cover,
                          height: 200.0,
                          width: 130.0,
                        ),
                        clipBehavior: Clip.antiAlias,
                        margin: EdgeInsets.all(8.0),
                      ),
                      Text(
                        async.data[position].title,
                        style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
                      )
                    ],
                  );
                });
           }
         }
     ),
   )
  ],
);

return listView;}

Upvotes: 10

Views: 20059

Answers (4)

AnasSafi
AnasSafi

Reputation: 6264

Wrap GridView widget with SizedBox widget and give it height and width values like this:

SizedBox(
  height: 100,
  width: double.infinity, // (double.infinity) to fill screen width
  child: GridView.count(
    // your GridView code ...
  ),
); 

Upvotes: 0

Bahaa Shammout
Bahaa Shammout

Reputation: 31

***wrap your inner listview with a container and give it a height. ***

Upvotes: 2

Conrad Mota
Conrad Mota

Reputation: 101

For me worked just wrapping the CustomScrollView or ListView with a Container. Like this:

 Container(
                margin: EdgeInsets.all(5.0),
                height: 295.0,
                width: 333.0,
                child: CustomScrollView(),
              ),

Upvotes: 10

Emmanuel Okocha
Emmanuel Okocha

Reputation: 397

So I finally solved the problem of this particular method by doing the following:

  1. enclosing the FutureBuilder in a container;
  2. giving the container width and height;
  3. adding it to a ListView.

Here is the code:

    Widget _featuredListHorizontal() {   
      return Container(
        margin: const EdgeInsets.symmetric(vertical: 20.0),
        height: 300.0,
        child: FutureBuilder(
          future: _trendingListImages(),
          builder: (BuildContext context, AsyncSnapshot listData) {
            if (listData == null) {
              return ColorLoader3(
                radius: 20.0,
                dotRadius: 5.0,
              );
            } else {
              return ListView.builder(
                shrinkWrap: true,
                physics: ClampingScrollPhysics(),
                scrollDirection: Axis.horizontal,
                itemCount: listData.data.length,
                itemBuilder: (BuildContext context, int position) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Card(
                        elevation: 18.0,
                        shape: const RoundedRectangleBorder(
                            borderRadius:
                            BorderRadius.all(Radius.circular(10.0))),
                        clipBehavior: Clip.antiAlias,
                        margin: const EdgeInsets.all(8.0),
                        child: Image.network(
                          "http://image.tmdb.org/t/p/w500/${listData.data[position].backdropPath}",
                          fit: BoxFit.cover,
                          height: 200.0,
                          width: 230.0,
                        ),
                      ),
                      Text(
                        listData.data[position].title,
                        style: TextStyle(
                            fontSize: 12.0,
                            fontWeight: FontWeight.bold,
                            color: Colors.white),
                      ),
                    ],
                  );
                },
              );
            }
          },
        ),   
      ); 
    }

Upvotes: 4

Related Questions