1

A recurring issue I have in my Flutter learning journey, is that GridView does require a parent container with a specified height.

What is the best practice to maximize the height so that it stretches out as much as needed without always incurring in overflow issues or unpleasant UI?

Here are a few methods I tried:

double.infinity - This one doesn't work properly, GridView doesn't show at all.

Container(
  height: double.infinity,
  child: GridView.builder(
    ....
)

MediaQuery.of(context).size.height - This one doesn't work properly either, overflow issues occur and just doesn't work completely when other elements are displayed (for example in a column).

Container(
  height: MediaQuery.of(context).size.height,
  child: GridView.builder(
    ....
)

fixed size - This one doesn't allow any flexibility at all and isn't ideal for responsiveness too.

Container(
  height: 800,
  child: GridView.builder(
    ....
)

Thank you.

1 Answer 1

3

Instead of using Container try to use Flexible widget.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! Wrapping a Flexible widget around the container of the GridView provides exactly the result I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.