Flutter setState() or markNeedsBuild() called when widget tree was locked

As a workaround wrap your code that calling setState into WidgetsBinding.addPostFrameCallback:

WidgetsBinding.instance
        .addPostFrameCallback((_) => setState(() {}));

That way you can be sure it gets executed after the current widget is built.

Leave a Comment