0

I have a TextField with an onSubmit callback. In this callback, I do some sets, then call setState(() {}); and finally do another property set. In tracing this code through the debugger, the onSubmit is completing all the lines and then the setState is occurring. So it doesn't appear setState is being called synchronously. If I remove the setState, no refresh occurs so I am pretty sure the setState is not coming from somewhere else. What am I missing?

Offending code:

    Function secToAnsOnSubmit = (String value) {
      int integer = int.tryParse(value);
      if (integer != null && integer >= qzCfgInfListsMl.secondsToAnswerMin) {
        qzCfgInfListsMl.secondsToAnswer = integer;
      }    
      setState(() {});
      _textEditingControllerInUse1 = false;
    };
rss181919
  • 427
  • 1
  • 5
  • 16
  • I see this post which might be related but it doesn't make sense to me because it undermines the documentation on setState which says it must be synchronous. https://stackoverflow.com/questions/59555999/setstate-doesnt-execute-until-the-enclosing-function-returns – rss181919 Dec 06 '20 at 03:32
  • If I cannot count on setState being synchronous, I can't ensure the property _textEditingControllerInUse1 gets updated after the view is refreshed. At least not without some additional coding I hope is not needed just to accomplish this simple task. – rss181919 Dec 06 '20 at 03:41

0 Answers0