Home > Back-end >  Flutter Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#a2797 relayo
Flutter Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#a2797 relayo

Time:10-18

I am working on Listview converting GridView but not showing Grid and get this error. I also try to wrap Expanded in GridView.builder

 child: GridView.builder(
                  gridDelegate:
                      const SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 2,
                  ),
                  itemBuilder: (context, index) {
                    final item = catalog.items![index];
                    return Card(
         
                      child: GridTile(
                        header: Container(
                          child: Text(
                            item.name,
                            style: TextStyle(color: Colors.white),
                          ),
                          padding: EdgeInsets.all(12),
                          decoration:
                              BoxDecoration(color: Colors.deepPurple),
                        ),
                        child: Image.network(item.image),
                        footer: Container(
                          child: Text(
                            item.price.toString(),
                            style: TextStyle(
                              color: Colors.white,
                            ),
                          ),
                        ),
                      ),
                    );
                  },
                ) 

CodePudding user response:

Use shrinkWrap : true inside GridView.Builder

CodePudding user response:

Try with calling itemCount on GridView.builder(

GridView.builder(
  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
    crossAxisCount: 2,
  ),
  itemCount: item.length, //this
  itemBuilder: (context, index) {

Also have the Expanaded widget if it inside Colum widget.

CodePudding user response:

Adding item count length through get data

child: GridView.builder(
              gridDelegate:
                  const SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2,
              ),
              itemCount: catalog.items!.length, //Adding This to Solved
              itemBuilder: (context, index) {
                final item = catalog.items![index];
                return Card(
     
                  child: GridTile(
                    header: Container(
                      child: Text(
                        item.name,
                        style: TextStyle(color: Colors.white),
                      ),
                      padding: EdgeInsets.all(12),
                      decoration:
                          BoxDecoration(color: Colors.deepPurple),
                    ),
                    child: Image.network(item.image),
                    footer: Container(
                      child: Text(
                        item.price.toString(),
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                    ),
                  ),
                );
              },
            ) 
  • Related