0

I am trying to create a widget where I have a listview and one of its children is a gridview.but I get this error:

Another exception was thrown: RenderBox was not laid out: RenderViewport#45df5 NEEDS-LAYOUT NEEDS-PAIN

when I remove the gridview the error goes away. here is my code:

ListView(
      children: <Widget>[
        Stack(
          overflow: Overflow.visible,
          children: <Widget>[
            _buildSlider(context),
            _buildAppBar(context),
          ],
        ),
         GridView.builder(
            itemCount: state.homePageData.categories.length,
            gridDelegate:
                SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
            itemBuilder: (BuildContext context, int index) {
              return Card(
                child: GridTile(
                  header: Text(state.homePageData.categories[index].name),
                  child: Image.network(baseUrl +
                      state.homePageData.categories[index].img.toString(),height: 50,width: 50,),
                ),
              );
            },
          )
      ],
    )
geekymano
  • 1,420
  • 5
  • 22
  • 53
  • 1
    Possible duplicate of [Flutter: RenderBox was not laid out](https://stackoverflow.com/questions/52801201/flutter-renderbox-was-not-laid-out) – rmtmckenzie May 09 '19 at 18:51
  • This is a duplicate of https://stackoverflow.com/questions/52801201/flutter-renderbox-was-not-laid-out?rq=1. The issue is that you're making something that expands as big or small as it can in the space it has, in something that lets things expand to zero or infinity (the list), so flutter doesn't know how to size the item. As it says in the other question's answer (with a little extrapolating), you can wrap the gridview in an expanded to solve this. – rmtmckenzie May 09 '19 at 18:53

0 Answers0