Flutter RenderObject assertion failure

Issue

I am having the following error :

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
Updated layout information required for RenderIndexedSemantics#f51aa NEEDS-LAYOUT to calculate semantics.
'package:flutter/src/rendering/object.dart':
Failed assertion: line 2658 pos 12: '!_needsLayout'


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack: 
#2      RenderObject._getSemanticsForParent (package:flutter/src/rendering/object.dart:2658:12)
#3      RenderObject._getSemanticsForParent.<anonymous closure> (package:flutter/src/rendering/object.dart:2680:61)
#4      Iterable.forEach (dart:core/iterable.dart:257:30)
#5      RenderSliverVariableSizeBoxAdaptor.visitChildren (package:flutter_staggered_grid_view/src/rendering/sliver_variable_size_box_adaptor.dart:296:29)
#6      RenderObject.visitChildrenForSemantics (package:flutter/src/rendering/object.dart:2765:5)
...
====================================================================================================

I would like to know what does it mean and when this usually happens ?
I am using the flutter_staggered_grid_view: ^0.4.0 package.

I will create a GitHub issue if needed.

Edit :
Here is a piece of code to highlight the problem :

My main Widget is rendered by :

StaggeredGridView.countBuilder(
      itemBuilder: (BuildContext context, int index) {
        return MyCustomItem();
      },
      padding: EdgeInsets.only(left: Constants.maxWidth*2/100, right: Constants.maxWidth*2/100,
          bottom: Constants.maxHeight*10/100 + 65), // home button size + margin bottom
      crossAxisCount: 2,
      mainAxisSpacing: 20,
      crossAxisSpacing: Constants.maxWidth*2/100,
      itemCount: 30,
      physics: BouncingScrollPhysics(),
      staggeredTileBuilder: (int index) {
        return StaggeredTile.fit(1);
      },
    ),

And MyCustomItem Widget that compose each item of the List :

Column(
      children: [
        GestureDetector(
          child:
          Container(
            margin: (widget.index == 0 || widget.index == 1) ? EdgeInsets.only(top: Constants.maxHeight*6/100+60) : EdgeInsets.all(0),
            //width: postWidth,
            // TODO : post height
            child: ClipRRect(
              borderRadius: BorderRadius.all(Radius.circular(20)),
              child: Image.asset("assets/images/test.jpg"), // TODO 
            ),
          ),
          onTap: () {
            // TODO
          },
          onDoubleTap: () {
            // TODO
          },
        ),
        Row(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: [
                GestureDetector(child:
                Container(
                  margin: EdgeInsets.only(top: 10, bottom: 3),
                  width: 35,
                  height: 35,
                ),
                  onTap: () {
                    // TODO 
                  },
                ),
                Flexible(child:
                Container(
                  width: Constants.maxWidth*25/100,
                  child:
                  Text(
                    "tessssst",
                    textAlign: TextAlign.center,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 14,
                      fontWeight: FontWeight.bold,
                      color: Color(resColors.getShadow()),
                    ),
                    maxLines: 1,
                  ),
                ),
                ),
              ],
            ),
            Spacer(),
            Container(
              margin: EdgeInsets.only(right: Constants.maxWidth * 2 / 100),
              child: Column(children: [
                Container(
                  margin: EdgeInsets.only(bottom: 3, top: 10),
                  child: InkWell(
                    onTap: () {
                      // TODO
                    },
                    highlightColor: Colors.transparent,
                    splashColor: Colors.transparent,
                  ),
                ),
                Text("1029"),
              ]),
            ),
            Container(
              child: Column(children: [
                Container(
                  margin: EdgeInsets.only(bottom: 3, top: 10, right: Constants.maxWidth/100),
                  child: InkWell(
                    onTap: () => {},// TODO
                    highlightColor: Colors.transparent,
                    splashColor: Colors.transparent,
                  ),
                ),
                Text("Test"),
              ]),
            ),
          ],
        )
      ],
    );

I would add that if MyCustomItem would be only a Text Widget I have not the error.

Solution

You can use now the new branch of the flutter_staggered_grid_view repo that is currently under tests, but it has fixed this issue for me.

The owner has stated that this is a complete refactor of the plugin that fixes many bugs.

Answered By – nicover

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *