Home > Blockchain >  Incorrect use of ParentDataWidget Error Flutter
Incorrect use of ParentDataWidget Error Flutter

Time:02-03

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?

CodePudding user response:

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

child: GridView(
  shrinkWrap: true,
  gridDelegate: 

CodePudding user response:

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(...)
    )
)
  •  Tags:  
  • Related