plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

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

Open dxvid-pts opened this issue 2 years ago • 2 comments

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

dxvid-pts avatar Feb 15 '24 21:02 dxvid-pts

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.

vbuberen avatar Feb 19 '24 09:02 vbuberen

@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?

IchordeDionysos avatar Feb 20 '24 15:02 IchordeDionysos

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: https://github.com/fluttercommunity/plus_plugins/compare/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 avatar Feb 28 '24 14:02 miquelbeltran

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

miquelbeltran avatar Feb 28 '24 14:02 miquelbeltran

@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()

navaronbracke avatar Feb 28 '24 14:02 navaronbracke

That's even better, thank you!

miquelbeltran avatar Feb 28 '24 15:02 miquelbeltran