Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GridView.builder with card has overflow and is not scrollable

I have a problem in making cards with gridview and it isnt scrollable. Below is the code:

GridView.builder(
              gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2, // number of items in each row
                mainAxisSpacing: 8.0, // spacing between rows
                crossAxisSpacing: 8.0, // spacing between columns
                childAspectRatio: (0.5),
              ),
              scrollDirection: Axis.vertical,
              shrinkWrap: true,
              padding: EdgeInsets.all(MediaQuery.of(context).size.width *
                  1 /
                  15), // padding around the grid
              itemCount: CoffeeList.length,
              itemBuilder: (context, index) {
                Coffee cof = CoffeeList[index];
                return Container(
                    height: 250,
                    child: Card(
                        margin: const EdgeInsets.all(4),
                        child: Column(children: <Widget>[
                          Center(
                              child: Stack(children: <Widget>[
                            Container(
                              width:
                                  MediaQuery.of(context).size.width * 47 / 125,
                              height:
                                  MediaQuery.of(context).size.width * 47 / 125,
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(12),
                                  image: DecorationImage(
                                      image: AssetImage((cof.imageAsset)),
                                      fit: BoxFit.fill)),
                            ),
                            Container(
                              width: 60,
                              height: 30,
                              decoration: BoxDecoration(
                                  color: Colors.black.withOpacity(0.20),
                                  borderRadius: const BorderRadius.only(
                                      topLeft: Radius.circular(16),
                                      bottomRight: Radius.circular(16))),
                            ),
                            const Padding(
                                padding: EdgeInsets.symmetric(
                                    vertical: 5, horizontal: 5),
                                child: Icon(
                                  Icons.star_rounded,
                                  color: Colors.yellow,
                                  size: 20,
                                )),
                            Padding(
                                padding: const EdgeInsets.symmetric(
                                    horizontal: 28, vertical: 5),
                                child: Text(cof.star.toString(),
                                    style: const TextStyle(
                                        color: Colors.white,
                                        fontSize: 14,
                                        fontWeight: FontWeight.w600)))
                          ])),
                          Padding(
                              padding: EdgeInsets.symmetric(
                                  vertical: 12, horizontal: 6),
                              child: Text(cof.type,
                                  style: TextStyle(
                                    fontSize: 16,
                                    fontWeight: FontWeight.w600,
                                  )))
                        ])));
              },
            ),

Please ignore the large chunks of empty spaces as I wanted to deal with the overflow before adding more things.

Problem

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve tried using physics (NeverScrollableScrollPhysics) in GridView.builder and SingleChildScrollView yet nothing works

>Solution :

Wrap it with widgets like Flexible or Expanded if you put GridView inside Column or Row. If it is not then please share full widget tree, which covers this GridView

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading