skip to Main Content
SizedBox(
                              height: 50,
                              child: GridView.builder(
                                shrinkWrap: false,
                                itemCount: 4,
                                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4, childAspectRatio: 1),
                                itemBuilder: (context, index) {
                                  return Container(height: 25, width: 25);
                                },
                              ),
                            )

Despite setting an explicit height of 25 on the Container children when the Containers are rendered they’re given a height of 83? And I can’t stop the containers from overflowing the GridView which has an explicit height of 50?

enter image description here

2

Answers


  1. I think the SizedBox size is ignored by its parent because of missing alignment value. Try wrapping it in Align widget or any widget that can align it child/children: Row, Column, Container with Alignment property,…

    Login or Signup to reply.
  2. You can set mainAxisExtent property for SliverGridDelegateWithFixedCrossAxisCount or use

    gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
         childAspectRatio: height / width,
         maxCrossAxisExtent: width,
    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search