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?
In a programming language like Java, developers can create multiple threads and share the same memory. Dart allows us to create multiple Isolates what is similar to multithreading, but it's not.
Dart/Flutter is single threaded and not possible to share global variable. As each isolate has its own memory,space and everything. To make it work like multi threaded you have to use isolates and the communication will be used through ports by sending message to one another.
Flutter is mainly single thread. Why so? Because Dart language is a single threaded language. However, Flutter uses several threads to do its work.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With