PostHog / posthog-flutter

PostHog Flutter SDK
https://posthog.com/docs/libraries/flutter
MIT License
55 stars 37 forks source link

support flutter web wasm builds #112

Open lukepighetti opened 4 months ago

lukepighetti commented 4 months ago

Version

4.5.0

Steps to Reproduce

in a flutter web project, build it with flutter build web --wasm

Expected Result

it builds

Actual Result

it doesn't build

More Context

flutter web wasm builds are now in stable branch and it is now a reasonable expectation for packages to support it https://docs.flutter.dev/platform-integration/web/wasm

marandaneto commented 3 months ago

Thanks for creating the issue.

We'd need to:

Migrate your packages to package:web and dart:js_interop to make them compatible with Wasm. Read the Requires JS-interop section to learn more.

mainly the posthog_flutter_web.dart and posthog_flutter_web_handler.dart files would need to be changed. Something to check is if after the migration it's still compatible with older Flutter versions (that's a must I'd say otherwise we'd need a major bump).

While we'd like to support it, it's still a low priority since there are a few limitations to running wasm on the browser so we'd not do this right now but soonish, of course PRs are welcome, happy to guide anyway lending a hand here.

flowhorn commented 3 months ago

I tried a little PR, currently I have issues with flutter 3.24 so I couldn't test it again when filing the PR, but this should work using dart:js_interop instead of dart:js.

Feel free to use this PR/adjust it etc.

https://github.com/PostHog/posthog-flutter/pull/114

marandaneto commented 3 months ago

I tried a little PR, currently I have issues with flutter 3.24 so I couldn't test it again when filing the PR, but this should work using dart:js_interop instead of dart:js.

Feel free to use this PR/adjust it etc.

114

a few things have to be fixed such as:

call.arguments['properties'] as Map<Object?, Object?>? ?? {} so the extension jsify is recognized. For some reason the cast has to be always to Map<Object?, Object?> even though its declared as Map<String, Object>? properties, the method channel is always converting during the invokeMethod call, plus test that everything works as expected, but thanks for the initial PR @flowhorn