I have a button which calls a long running function which runs some kind of loop:
void runLongRunningFunction() {
for (int i = 0; i < 100000; i++) {
doSth();
}
}
...
onPressed: () {
runLongRunningFunction();
}
Now I want to reach two goals:
- The function should not block the UI: Currently the UI freezes as long as the function runs.
- Instead it should show some kind of progress, maybe a
Text()
widget which updates a percentage or even better, a progress bar.
So:
- How can I decouple the function from the UI?
- How can I return some intermediate values from the function calculation (e.g. the current value of the iterator i) to the UI to update my progress view while the function is still running?
Thanks in advance!