You currently have:
setState(() {
futureWait = "$fifteen second wait for both futures completed";
});
futureWaitBool = true;
You’re asking:
You call setState(fn).
Flutter:
After the current Dart event loop completes (i.e. after your function returns), Flutter’s scheduler triggers a rebuild for all dirty widgets before the next frame is rendered.
setState
completes, before the next frame is rendered.setState(() {
futureWait = "...";
});
futureWaitBool = true;
No race condition (because both statements run sequentially on the main isolate).
However, you updated futureWaitBool
outside of setState
, so:
futureWaitBool
changed.setState
is called later.Wrap all state changes that affect your UI within the same setState()
call:
setState(() {
futureWait = "$fifteen second wait for both futures completed";
futureWaitBool = true;
});
This ensures:
Official docs state:
“Calling setState notifies the framework that the internal state of this object has changed ... which causes the framework to schedule a build for this State object.”
Summary:
setState
completes.setState
implementation.No race conditions here. setState:
Always update all UI-affecting state inside setState() for predictable behavior.