setState() or markNeedsBuild called during build

后端 未结 6 1667
自闭症患者
自闭症患者 2020-12-04 16:14
class MyHome extends StatefulWidget {
  @override
  State createState() => new MyHomePage2();
}

class MyHomePage2 extends State

        
6条回答
  •  清歌不尽
    2020-12-04 16:57

    I was also setting the state during build, so, I deferred it to the next tick and it worked.

    previously

    myFunction()
    

    New

    Future.delayed(Duration.zero, () async {
      myFunction();
    });
    

提交回复
热议问题