Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"threads" in Dart using Flutter for web

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?

like image 622
Albert Avatar asked Mar 23 '21 09:03

Albert


People also ask

Does Dart support multithreading?

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.

Does Flutter support multithreading?

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.

Is Flutter multithreaded or single threaded?

Flutter is mainly single thread. Why so? Because Dart language is a single threaded language. However, Flutter uses several threads to do its work.


1 Answers

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

like image 57
Sarvesh Dalvi Avatar answered Sep 17 '22 09:09

Sarvesh Dalvi