我正在尝试在controller.value == 0时触发showDialog()。我在GestureDetecter中尝试了相同的对话框,并且效果很好。但是当我在计时器结束时触发它时,会显示此错误..在构建过程中调用setState()或markneedsbuild()。我从本文https://www.didierboelens.com/faq/week2/中知道发生这种情况的原因,但我不知道如何解决此问题。因为我需要在计时器达到0.00时显示showDialog。
/*** ---------- not working ----------------- **/ AnimatedBuilder( animation: controller, builder: (BuildContext context, Widget child) { return controller.value == 0? autoSubmition() : Container(); }, ),//shows this error setState() or markneedsbuild() called during build error autoSubmition() { //model.setTestTimerRunning(false); var autoResponse = { "submitDialogTitle": "Your have ran out of time. Please Submit you answer", "submitDialogSubtitle": "If you cancel this test will be terminated. Your score will be reset to zero" }; showDialog( context: context, barrierDismissible: false, builder: (_) { return AutoSubmitTestDialog( context: context, model: model, testItem: testItem, messages: autoResponse); }, ); } /*** --------------- ******* ----------------- **/ /*** --------------- working ----------------- **/ GestureDetector( onTap: () async { model.setTestTimerRunning(false); var response = await model.checkBeforeSubmitTest(testItem); autoSubmition(); // show dialog function }, child: -------- ), /*** --------------- ******* ----------------- **/
再次,我知道发生这种情况的原因,我只是不知道如何实现。。
我正在尝试在controller.value == 0时触发showDialog()。我在GestureDetecter中尝试了相同的对话框,并且效果很好。但是当我在计时器结束时触发它时,会显示此错误。.setState()...
尝试一下:
您可以在下面复制粘贴运行完整代码如果0
表示AnimationStatus.completed
,则可以监听此事件并弹出对话框