Dart : Isolate not working when using html import

Issue

I found this very strange and unfortunate behavior in Dart. When I import ‘dart:html’ in my main file, my Isolate stops working.

With my file “isolate.dart” :

main(){
  print('BAM');
}

This prints “BAM”:

import 'dart:core';
import 'dart:isolate';

void main() {
  Isolate.spawnUri(Uri.parse('isolate.dart'), [], null);
}

but this prints nothing :

import 'dart:core';
import 'dart:isolate';
import 'dart:html';

void main() {
  Isolate.spawnUri(Uri.parse('isolate.dart'), [], null);
}

How can I get Isolate to work while using the html import?

UPDATE :
I’ve found this code https://github.com/TomCaserta/ExampleIsolate and tried to work it to find the problem. It seems like the print() call from the Isolate is causing problems.

Solution

This are known bugs/limitations. It is being worked on.

Currently it is not possible to access functionality of the ‘dart:html’ package in an isolate and ‘print()’ crashes the isolate probably because there is no package with a ‘print’ functionality available where the command can be redirected to.

The Dart issue tracker seems not to be available currently.
I try again later to add some references.

Some open issues that I think are related:

Answered By – Günter Zöchbauer

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *