Open WieFel opened 2 hours ago
Hi @WieFel
Have you run the dart run isolate_manager:generate
and is it completed?
If the csv
and excel
support the Dart native then the isolate should work after the generation is complete.
Thanks for the quick answer.
Yes, I ran dart run isolate_manager:generate
, and it generated two files exportAsCsv.js
and exportAsExcel.js
.
And yes, the packages actually both support web: https://pub.dev/packages/csv https://pub.dev/packages/excel
When I run them just with the normal dart compute()
function, they run fine on the web, but they block the UI of course.
I just don't really understand what the UnimplementedError
tells me in this case, as the js code is obfuscated...
I think the issue is caused by excel.save
, it executes the download dialog which isn’t supported on the Worker.
Is there any other method that does the same without triggering the native UI part like dialog?
True, it is triggering the download directly. But no download dialog.
However, exportAsCsv
doesn't do that, and still fails. I also triggered exportAsCsv
in the example that failed...
You can try using the List
@isolateManagerWorker
Future<List> exportAsCsv(List data) async {
final csv = ListToCsvConverter().convert(data);
return csv.codeUnits;
}
I just tried it even without using the external csv
lib:
@pragma('vm:entry-point')
@isolateManagerWorker
Future<List> exportAsCsv(List data) async {
final csv = data.map((d) => d.join(',')).join('\n');
return csv.codeUnits;
}
But after re-executing dart run isolate_manager:generate
and restarting my web application from scratch, I still get the same error:
Uncaught Error: UnimplementedError
at Object.b (exportAsCsv.js:250:18)
at Object.bP (exportAsCsv.js:259:15)
at ci.gb_ (exportAsCsv.js:3881:16)
at exportAsCsv.js:2005:3
at fr.a (exportAsCsv.js:1318:64)
at fr.$2 (exportAsCsv.js:2448:14)
at Object.h0 (exportAsCsv.js:1304:11)
at Object.hb (exportAsCsv.js:2008:10)
at kN (exportAsCsv.js:2041:3)
at exportAsCsv.js:4348:66
Line 250
in exportAsCsv.js
looks like this:
b(a){return A.ih(new Error(),a)},
Line 4348
in exportAsCsv.js
is:
if(typeof dartMainRunner==="function"){dartMainRunner(s,[])}else{s([])}})})()
I have the following code, which I run on an isolate. It has two functions
exportAsCsv
andexportAsExcel
(in a separate dart file), which depend on an external lib respectively.I instantiate the isolate managers like this in my Bloc:
On Android/iOS, the code runs fine. When I run it on web, and trigger e.g. the
exportToCsv()
function, I get the following error in my browser console:I suppose that is due to
isolate_manager
not supporting ANY external packages.. Is that true? Is there any way I can get it to work on web?