Closed sabin26 closed 9 months ago
That's because JavaScript knows nothing about Dart strong types and generics, so any List<T>
and Map<K,V>
crossing the Web worker boundary becomes a plain List<dynamic>
and Map, dynamic, dynamic>
on the receiving end.
Try changing factory HttpResponse.fromJson(final Map<String, Object?> json)
to factory HttpResponse.fromJson(final Map json)
and you should be OK.
But then, it will probably choke on as List<int>
and as Map<String, dynamic>
. To fix that and regain strong types, you can write this instead:
json['bodyBytes']!.cast<int>(),
...
headers: json['headers']!.cast<String, String>()
...
Thank you so much. It worked. It did not choke on List
I am returning this model class from squadron worker. Why is it that this works on isolates but not on web workers ? I do not see any data type that should not be transferred from web worker but still I am getting an exception. There are
fromJson
andtoJson
methods that work on Dart VM but not on web.Here is the exception (Screenshot):