11

I'm currently implementing a simulation for some mathematical problems. Since Flutter has such an easy way to create user interfaces and has web-support, I decided to use Flutter for this project. So far, everything works perfectly. The problem however is that in one simulation, each step takes some time to process (with problem size 128 it takes ~14 seconds) during which the whole user interface freezes. I found that this can be solved using isolates however this is not supported for web. Is there any other approach to tackle this?

Alb
  • 1,063
  • 9
  • 33
  • maybe have a look at async programming https://dart.dev/codelabs/async-await – Tinus Jackson Mar 23 '21 at 10:01
  • @TinusJackson I tried that. The step of the problem is triggered by an onPressed, which executes an `async` function. This didn't prevent the GUI from freezing so I tried to make the functions called in this trigger to be `async` as well. Unfortunately, this has not helped, no matter how deep I go and make functions `async` – Alb Mar 23 '21 at 10:04
  • 1
    @TinusJackson Async programming differs from multi-threading. In async programming your device call an async function and wait for it to provide the required result. There is no computation goin on in the background then. In multi-threading, your device calls the fucntions and starts doing computation in the background. Async functions work on the same UI thread whereas Isolates functions compute on a completely different thread – Sarvesh Dalvi Mar 23 '21 at 10:06
  • @SarveshDalvi I am aware. Unfortunately, Isolates are not supported for web. Is there a way to prevent my GUI from freezing while a process computes in the background? – Alb Mar 23 '21 at 10:07
  • @Albert You can refer the solution I have provided. You baiscally use html workers instead of isolates – Sarvesh Dalvi Mar 23 '21 at 10:08

1 Answers1

1

https://dev.to/kyorohiro/isolate-at-flutter-for-web-28lg#:~:text=We%20could%20use%20isolate%20in,Use%20Worker%20instead%20of%20Isolate. This link will help. You can use workers which were used when isolates were not supported in dart.

This one too : https://github.com/deakjahn/flutter_isolate_web has a good example of it's implementation

Sarvesh Dalvi
  • 2,260
  • 2
  • 14
  • 30