incrediblezayed / file_saver

A simple flutter plugin for saving files in all platforms
https://pub.dev/packages/file_saver
BSD 3-Clause "New" or "Revised" License
75 stars 103 forks source link

Fix: Update conditional import to use correct library for wasm #117

Closed jthlim closed 3 months ago

jthlim commented 5 months ago

The current file_saver builds for wasm, but trying to use it immediately fails with "Cannot create PlatformHandler"

This is because the conditional import on dart.library.html does not happen on wasm.

From https://dart.dev/interop/js-interop/package-web#conditional-imports

Screenshot 2024-05-31 at 2 36 43 PM

This shows that dart.library.html should be replaced with dart.library.js_interop

This PR does just that.

With this change, I have tested that I get a working file save under wasm now.

myxzlpltk commented 5 months ago

small piece forgotten. lgtm 👍

Rachel030219 commented 5 months ago

I'm still unable to build wasm using flutter build web --wasm after applying this patch, getting errors like below:

../../../.pub-cache/hosted/pub.flutter-io.cn/path_provider_windows-2.2.1/lib/src/path_provider_windows_real.dart:5:1: Error: 'dart:ffi' can't be imported when compiling to
Wasm.
import 'dart:ffi';
../../../.pub-cache/hosted/pub.flutter-io.cn/path_provider_linux-2.2.1/lib/src/get_application_id_real.dart:5:1: Error: 'dart:ffi' can't be imported when compiling to Wasm.
import 'dart:ffi';
^

Is there a way to import path_provider_windows and path_provider_linux merely on Windows / Linux to avoid them interrupting wasm build?

jthlim commented 5 months ago

That looks like an issue with path_provider - not with file_saver. You should post issues related to path_provider in that repo, not file_saver.

Rachel030219 commented 5 months ago

That looks like an issue with path_provider - not with file_saver. You should post issues related to path_provider in that repo, not file_saver.

It should be, but the path_provider_windows and _linux dependencies are declared in file_saver's pubspec.yaml and imported in utils/helpers.dart, causing wasm build failure. Tried to remove those (use path_provider only, on all desktop platforms) and wasm was built correctly, but I'm not sure if it will build and work correctly on Windows and Linux.

Brada-Groep commented 3 months ago

Can this please be merged? :)