Skip to content

[Request]: (connectivity_plus): migrate to pkg:web from dart:html #2600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dxvid-pts opened this issue Feb 15, 2024 · 6 comments · Fixed by #2621
Closed

[Request]: (connectivity_plus): migrate to pkg:web from dart:html #2600

dxvid-pts opened this issue Feb 15, 2024 · 6 comments · Fixed by #2621
Assignees
Labels
enhancement New feature or request triage

Comments

@dxvid-pts
Copy link

Plugin

connectivity_plus

Use case

Flutter web apps are required to migrate from dart:html to package:web to use WASM.

Proposal

This issue tracks the upgrade process for connectivity_plus.

See https://docs.flutter.dev/platform-integration/web/wasm and https://pub.dev/packages/web for more information

@vbuberen
Copy link
Collaborator

Thanks for raising this, but we already track it since November and had a discussions about such migration with some people in the Dart team. The migration for this and other packages will happen when web package has all the required APIs ready for the corresponding plugin.

@IchordeDionysos
Copy link
Contributor

@vbuberen are there corresponding issues for those on the Dart side?
Ones we could like here?
Would there be anything we could do to speed it up?

@miquelbeltran
Copy link
Member

Does anyone know if there is a migration guide somewhere? I'm currently checking if moving to the web package would be possible, but the implementation on listening to events has changed, and I cannot figure it out.

The wip branch: main...miquelbeltran/issue2600

This code here does not compile:

window.ononline.listen((event) {

The method 'listen' isn't defined for the type 'JSFunction'.
Try correcting the name to the name of an existing method, or defining a method named 'listen'.dartundefined_method
Type: InvalidType

And I cannot find any examples out there on how to listen to events defined as EventHandler (a superclass of JSFunction). Anyone knows?

@miquelbeltran
Copy link
Member

This example from url_launcher seems close enough:

https://github.com/flutter/packages/pull/5451/files#diff-77a04b3b00b00a4480b7d5e75e089dde7cca99ccebcc4f43e0e25d2bba5346e0R107-R111

there is a short migration guide but doesn't explain how the listening of events work now: https://dart.dev/interop/js-interop/package-web

@navaronbracke
Copy link
Contributor

navaronbracke commented Feb 28, 2024

@miquelbeltran you can add an event listener to the online event. (where the window is the event target)

See https://pub.dev/documentation/web/latest/web/EventStreamProviders/onlineEvent-constant.html
and https://pub.dev/documentation/web/latest/web/EventStreamProvider/forTarget.html

package:web provides various EventStreamProviders to bridge this API gap.

onlineEvent.forTarget(window).listen()

@miquelbeltran
Copy link
Member

That's even better, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants