Dart Isolate as permanent worker

Issue

I’m using Flutter and need to do some parsing. To prevent said parsing from blocking the UI, I’m using an Isolate ; however spawning the Isolate seems to have a big time cost (~2s on my Samsung A5, with the ‘compute’ fonction). Which is a bit stupid, since the parsing takes less time then that…
Since I don’t want my users to have to wait for 2 seconds ‘for free’, I’d like to launch an Isolate when the app starts, and just give it the parsing to do when I need to do it.

What is the best way to accomplish this in Dart ? There’s probably something better to do then a while(true) loop…

Thanks.

Solution

Can you try using the easy_isolate plugin? I tried here and took only 195ms to execute a code inside the isolate.

The Parallel.run works like the compute function. The plugin has well-explained documentation.

https://pub.dev/packages/easy_isolate

Answered By – Lucas Britto

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.