Skip to content
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

Migrate to package:web #122

Closed
navaronbracke opened this issue Nov 8, 2023 · 11 comments
Closed

Migrate to package:web #122

navaronbracke opened this issue Nov 8, 2023 · 11 comments

Comments

@navaronbracke
Copy link
Contributor

This issue is a proposal to migrate from dart:html to package:web.

This would unblock migrating google_maps_flutter_web in flutter/packages#5254

@a14n
Copy link
Owner

a14n commented Nov 8, 2023

The migration will not be a little task and I'd prefer that package:web 0.3.0 was not in preview and not with a This package is highly experimental warning.
That being said I'll try to find time to take a look. Is there some doc somewhere about this new package:web (and the underlying js-interop) ? /ping @kevmoo

@kevmoo
Copy link

kevmoo commented Nov 8, 2023

We don't have docs...yet. We're holding off because we're waiting on extension types to start encouraging migrations.

Look at this diff for inspiration, though: flutter/packages@main...pkg_web_wip

@kevmoo
Copy link

kevmoo commented Nov 8, 2023

You'll HAVE to do a branch – or depend on a dev SDK to do the migration.

Another option is to wait for the next Dart release!

@johnpryan
Copy link

I made a branch with some small tweaks to get the script running, but the generated code has a lot of errors:

master...johnpryan:dart-google-maps:pkg_web

@a14n have you had time to look at this lately?

@a14n
Copy link
Owner

a14n commented Dec 11, 2023

Not really for now but I just recover my setup and I will try to take a look soon (hopefully in the coming days/weeks)

@a14n
Copy link
Owner

a14n commented Dec 20, 2023

I just pushed a branch package-web containing the lib/ folder migrated to package:web. The example folder migration is in progress but you can already try the lib now.

The generator tool is not yet updated to use package:web instead of dart:html.

In the future I also plan to use static js interop but it requires more work so it is likely that this will not happen soon.

Side note about this migration : it was not obvious how to pass a JSFunction required by some functions like getCurrentLocation. I finally used a simple cast () {} as JSFunction that seems to work but that looks quite strange to me.

@navaronbracke
Copy link
Contributor Author

navaronbracke commented Dec 20, 2023

@a14n You can make a JSFunction out of a Dart function using:

import 'dart:js_interop'
import 'package:js/js.dart';

allowInterop((arg) {
  // ...
}).toJS

where the arg is a JS type accepted by the compiler (so all the primitives: String, bool, int, double, null, and also JS types JSArray, JSObject, JSAny)

If you have a JSFunction and you need to call it in Dart, use the callAsFunction() method https://api.flutter.dev/flutter/dart-js_interop/JSFunctionUtilExtension/callAsFunction.html

@a14n
Copy link
Owner

a14n commented Jan 10, 2024

I just push a 7.0.0-beta.1 version on pub you can use. Let me know when you test it and validate. Then I'll publish a 7.0.0.

@navaronbracke
Copy link
Contributor Author

navaronbracke commented Jan 11, 2024

I updated the mentioned branch to run with 7.0.0-beta.1 and the google_maps_flutter_web integration tests pass locally for me. So I think you can release it?

@navaronbracke
Copy link
Contributor Author

@a14n All the integration tests for google_maps_flutter_web pass locally for me. I think that is a good sign to publish google_maps: 7.0.0.

@a14n
Copy link
Owner

a14n commented Feb 8, 2024

google_maps-7.0.0 is now published.

@a14n a14n closed this as completed Feb 8, 2024
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

No branches or pull requests

4 participants