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

Flutter Gird View – Square items

I have created a grid view with GridView.count, with 3 items per row. The issue is the items are rectangular in shape while I want to make them square

Here’s the code:

Padding(
    padding: const EdgeInsets.symmetric(vertical: 8.0),
    child: GridView.count(
      crossAxisCount: 3,
      childAspectRatio: 1,
      children: categories
          .map((e) => Padding(
                padding: const EdgeInsets.symmetric(horizontal: 6),
                child: Card(
                  color: e.color,
                  elevation: 2,
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(12),
                      side: BorderSide(color: e.borderColor, width: 1.5)),
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Center(
                      child: Text(e.name,
                          textAlign: TextAlign.center,
                          style: const TextStyle(
                              fontSize: 14,
                              color: Colors.black,
                              fontWeight: FontWeight.w400)),
                    ),
                  ),
                ),
              ))
          .toList(),
    ),
  )

Here’s the screenshot:
enter image description here

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

Thanks in advance.

>Solution :

Remove the Padding around the Card and specify the spacing between the elements in your GridView using:

  • mainAxisSpacing
  • crossAxisSpacing
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