0

I'm trying to display grid view, but I got an error saying "Incorrect use of ParentDataWidget".

Here is my code:

 body: Container {
    ...
    child: Column {
       children : [
          Container {
             child: GridView(
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                   crossAxisCount: 4,
                ),
                children: [
                   CircleAvatar(
                      child: Icon(
                         Icons.person,
                      ),
                      backgroundColor: Colors.black,
                    ),
                    CircleAvatar(
                      child: Icon(
                         Icons.person,
                      ),
                      backgroundColor: Colors.black,
                    ),
                    CircleAvatar(
                      child: Icon(
                         Icons.person,
                      ),
                      backgroundColor: Colors.black,
                    ),
                ]
             )
          }
       ]
    }
 }

And here is the error:

  • Incorrect use of ParentDataWidget.
  • Vertical viewport was given unbounded height.
  • RenderBox was not laid out: RenderViewport#8c1a9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': Failed assertion: line 1927 pos 12: 'hasSize'

Any solutions?

1

2 Answers 2

0

On your GridView provide shrinkWrap: true,. This is also discussed Flutter Gridview in Column.

child: GridView(
  shrinkWrap: true,
  gridDelegate: 
Sign up to request clarification or add additional context in comments.

6 Comments

but I can't resize the circleavatar, tried using size and radius but I got an error saying "Incorrect use of ParentDataWidget."
GridView children's size depends on childAspectRatio, can be found inside gridDelegate
ah I see, thank you
For your case, you might be looking for Wrap
shrinkWrap is bad for performance if there are large number of items in the list. You can refer this youtu.be/LUqDNnv_dh0
|
0

You used GridView inside Column that is why flutter is giving error. Try wrapping GridView with Expanded or Flexible widget

Column(
     children: Expanded(
        child: GridView(...)
    )
)

Comments

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.