Skip to content

fix: use the web services under WASM and drop universal_io - #33

Open
Eimen2018 wants to merge 3 commits into
Stacked-Org:mainfrom
Eimen2018:fix/wasm-drop-universal-io
Open

Eimen2018 wants to merge 3 commits into
Stacked-Org:mainfrom
Eimen2018:fix/wasm-drop-universal-io

Conversation

@Eimen2018

Copy link
Copy Markdown
Collaborator

Summary

Fixes stacked_themes on WebAssembly builds and makes it WASM compatible on pub.dev. Refs Stacked-Org/stacked#1105.

Problems

  1. Wrong services under WASM. The web versions of PlatformService and StatusBarService were chosen with if (dart.library.js). That condition is false under dart2wasm, so a WASM build used the mobile services. On a mobile browser the mobile PlatformService reports Android or iOS, and themes then calls the flutter_statusbarcolor_ns plugin, which has no web implementation.

    Reproduced with flutter build web --wasm, an Android user agent, and a ThemeBuilder with statusBarColorBuilder:

    MissingPluginException(No implementation found for method setstatusbarcolor on channel plugins.sameer.com/statusbar)
    

    thrown uncaught on every theme change. The JavaScript build is not affected.

  2. Not WASM compatible on pub.dev. platform_service.dart imports universal_io, which resolves to a file importing dart:io under the wasm runtime. The latest universal_io is itself not WASM ready.

Change

  • StatusBarService: default to the web stub and pick the plugin-backed one with if (dart.library.io). That is false for both JavaScript and WASM web builds and works on every Dart version this package supports.
  • PlatformService: one implementation using kIsWeb and defaultTargetPlatform. Web still reports false for isIos and isAndroid, as the old web file did. platform_service_web.dart is removed.
  • pubspec.yaml: remove universal_io.

No public API change. Mobile behaviour is unchanged.

Verification

  • Same test app, same steps, this branch: clean console on desktop and with an Android user agent, running the .wasm module with no JS fallback.
  • pana on this branch: is:wasm-ready, platform support 20/20. On main it is not.
  • flutter test: 24 passed. flutter analyze: only the existing window deprecation info. dart format: clean.

Note: this PR comes from a fork, so the coverage comment step may fail with "Resource not accessible by integration". Format, analyze and test are the steps that matter.

🤖 Generated with Claude Code

The web PlatformService and StatusBarService were selected with
'if (dart.library.js)', which is false under dart2wasm. A WASM build
therefore used the mobile services, and on a mobile browser called the
status bar plugin, which has no web implementation.

Select the status bar service with 'if (dart.library.io)' instead, and
make PlatformService a single kIsWeb-aware implementation based on
defaultTargetPlatform, which also removes the universal_io dependency
that made pub.dev mark the package as not WASM compatible.

Refs Stacked-Org/stacked#1105

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant