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

前端 未结 7 1444
忘掉有多难
忘掉有多难 2020-12-03 06:45

I am having trouble finding the source to this exception, and the app is quite complex so it is hard to show any relevant part of the code. This is my repository at the poin

7条回答
  •  自闭症患者
    2020-12-03 07:34

    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.

提交回复
热议问题