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

[google_maps_flutter_web] Migrate to package:web #5254

Merged
merged 43 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8800cc7
depend on package:web
navaronbracke Oct 27, 2023
0c9fc45
fix comment
navaronbracke Oct 27, 2023
8960e3d
update import in base file
navaronbracke Oct 27, 2023
b420f32
depend on package web in the example app
navaronbracke Oct 28, 2023
a0637f1
add utility function to create divs
navaronbracke Oct 28, 2023
636e71f
migrate overlay.dart
navaronbracke Oct 28, 2023
639fe97
migrate markers.dart
navaronbracke Oct 28, 2023
c22678e
migrate marker.dart
navaronbracke Oct 28, 2023
147e570
migrate convert.dart
navaronbracke Oct 28, 2023
5ff2982
migrate google_maps_controller.dart
navaronbracke Oct 28, 2023
c4581dd
migrate google map controller test
navaronbracke Oct 28, 2023
0fb3d67
migrate markers test
navaronbracke Oct 28, 2023
9898737
migrate another markers test
navaronbracke Oct 28, 2023
18564d2
migrate overlay_test.dart
navaronbracke Oct 28, 2023
aa9533a
migrate overlays_test.dart
navaronbracke Oct 28, 2023
1667de9
migrate shapes_test.dart
navaronbracke Oct 28, 2023
c43f31e
add missing imports
navaronbracke Oct 28, 2023
a14981c
remove space
navaronbracke Oct 28, 2023
32d66fa
switch to pkg google_maps beta
navaronbracke Jan 11, 2024
788d35a
add casts due to pkg:web 0.4.0 removing "implements JSObject" from Blob
navaronbracke Jan 11, 2024
1040103
format
navaronbracke Jan 11, 2024
edc00a8
fix event listener type
navaronbracke Jan 11, 2024
cd2b0e8
add directionality
navaronbracke Jan 23, 2024
861f294
fix version constraint for pkg:web
navaronbracke Jan 23, 2024
bb8810f
fix type error in overlay test
navaronbracke Jan 23, 2024
e578d86
fix lint warnings
navaronbracke Jan 23, 2024
638a466
fix hanging test
navaronbracke Jan 23, 2024
75db30d
use .toJS on Function directly
navaronbracke Jan 23, 2024
2c086d2
fix test
navaronbracke Jan 31, 2024
fb7f53a
bump google_maps to 7.0.0
navaronbracke Feb 8, 2024
aee9770
remove the utility in integration tests
navaronbracke Feb 14, 2024
9f2716e
assert on Uint8List for the bitmap descriptor
navaronbracke Feb 14, 2024
cb9c665
use trusted types policy to sanitize html
navaronbracke Feb 14, 2024
aa46171
fix constructor
navaronbracke Feb 14, 2024
0523daa
fix argument
navaronbracke Feb 14, 2024
e2df4b1
handle undefined trusted types policy
navaronbracke Feb 15, 2024
e358399
bump version of google_maps_flutter_web
navaronbracke Feb 19, 2024
736aec1
fix license headers
navaronbracke Feb 19, 2024
8b4d7bb
adjust trusted types binding usage
navaronbracke Feb 23, 2024
d8adca1
fix quotes in pubspec & add ignore for upcoming lint
navaronbracke Feb 27, 2024
52baeca
add JS binding for MapStyler
navaronbracke Feb 27, 2024
1951a6a
set inner html to trusted html instance
navaronbracke Feb 27, 2024
6583739
Make getTTPolicy a little bit less generic looking.
ditman Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 0.5.5

* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1.
* Migrates to `dart:js_interop` and `package:web` APIs.
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.

## 0.5.4+3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:html' as html;

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps/google_maps.dart' as gmaps;
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
// ignore: implementation_imports
import 'package:google_maps_flutter_web/src/utils.dart';
import 'package:integration_test/integration_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
Expand Down Expand Up @@ -230,7 +231,7 @@ void main() {
polygons = MockPolygonsController();
polylines = MockPolylinesController();
tileOverlays = MockTileOverlaysController();
map = gmaps.GMap(html.DivElement());
map = gmaps.GMap(createDivElement());
});

testWidgets('listens to map events', (WidgetTester tester) async {
Expand Down Expand Up @@ -471,7 +472,7 @@ void main() {

setUp(() {
map = gmaps.GMap(
html.DivElement(),
createDivElement(),
gmaps.MapOptions()
..zoom = 10
..center = gmaps.LatLng(0, 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:html' as html;

import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps/google_maps.dart' as gmaps;
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
// ignore: implementation_imports
import 'package:google_maps_flutter_web/src/utils.dart';
navaronbracke marked this conversation as resolved.
Show resolved Hide resolved
import 'package:integration_test/integration_test.dart';

/// Test Markers
Expand Down Expand Up @@ -123,7 +124,7 @@ void main() {

testWidgets('showInfoWindow', (WidgetTester tester) async {
final gmaps.InfoWindow infoWindow = gmaps.InfoWindow();
final gmaps.GMap map = gmaps.GMap(html.DivElement());
final gmaps.GMap map = gmaps.GMap(createDivElement());
marker.set('map', map);
final MarkerController controller = MarkerController(
marker: marker,
Expand All @@ -138,7 +139,7 @@ void main() {

testWidgets('hideInfoWindow', (WidgetTester tester) async {
final gmaps.InfoWindow infoWindow = gmaps.InfoWindow();
final gmaps.GMap map = gmaps.GMap(html.DivElement());
final gmaps.GMap map = gmaps.GMap(createDivElement());
marker.set('map', map);
final MarkerController controller = MarkerController(
marker: marker,
Expand All @@ -156,7 +157,7 @@ void main() {

setUp(() {
final gmaps.InfoWindow infoWindow = gmaps.InfoWindow();
final gmaps.GMap map = gmaps.GMap(html.DivElement());
final gmaps.GMap map = gmaps.GMap(createDivElement());
marker.set('map', map);
controller = MarkerController(marker: marker, infoWindow: infoWindow);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

import 'dart:async';
import 'dart:convert';
import 'dart:html' as html;
import 'dart:typed_data';
import 'dart:ui';

import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps/google_maps.dart' as gmaps;
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
// ignore: implementation_imports
import 'package:google_maps_flutter_web/src/utils.dart';
import 'package:http/http.dart' as http;
import 'package:integration_test/integration_test.dart';
import 'package:web/web.dart';

import 'resources/icon_image_base64.dart';

Expand All @@ -28,7 +30,7 @@ void main() {
setUp(() {
events = StreamController<MapEvent<Object?>>();
controller = MarkersController(stream: events);
map = gmaps.GMap(html.DivElement());
map = gmaps.GMap(createDivElement());
controller.bindToMap(123, map);
});

Expand Down Expand Up @@ -274,11 +276,11 @@ void main() {
controller.addMarkers(markers);

expect(controller.markers.length, 1);
final html.HtmlElement? content = controller.markers[const MarkerId('1')]
?.infoWindow?.content as html.HtmlElement?;
expect(content?.innerHtml, contains('title for test'));
final HTMLElement? content = controller
.markers[const MarkerId('1')]?.infoWindow?.content as HTMLElement?;
expect(content?.innerHTML, contains('title for test'));
expect(
content?.innerHtml,
content?.innerHTML,
contains(
'<a href="https://www.google.com">Go to Google &gt;&gt;&gt;</a>',
));
Expand All @@ -299,8 +301,8 @@ void main() {
controller.addMarkers(markers);

expect(controller.markers.length, 1);
final html.HtmlElement? content = controller.markers[const MarkerId('1')]
?.infoWindow?.content as html.HtmlElement?;
final HTMLElement? content = controller
.markers[const MarkerId('1')]?.infoWindow?.content as HTMLElement?;

content?.click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// found in the LICENSE file.

import 'dart:convert';
import 'dart:html' as html;
import 'dart:js_interop';

import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps/google_maps.dart' as gmaps;
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
import 'package:integration_test/integration_test.dart';
import 'package:web/web.dart';

import 'resources/tile16_base64.dart';

Expand Down Expand Up @@ -43,8 +44,10 @@ void main() {
final gmaps.Size size = controller.gmMapType.tileSize!;
expect(size.width, TileOverlayController.logicalTileSize);
expect(size.height, TileOverlayController.logicalTileSize);
expect(controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, html.document),
null);
expect(
controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, document),
null,
);
});

testWidgets('produces image tiles', (WidgetTester tester) async {
Expand All @@ -55,16 +58,16 @@ void main() {
),
);

final html.ImageElement img =
controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, html.document)!
as html.ImageElement;
final HTMLImageElement img =
controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, document)!
as HTMLImageElement;
expect(img.naturalWidth, 0);
expect(img.naturalHeight, 0);
expect(img.hidden, true);

// Wait until the image is fully loaded and decoded before re-reading its attributes.
await img.onLoad.first;
await img.decode();

await img.decode().toDart;

expect(img.hidden, false);
expect(img.naturalWidth, 16);
Expand All @@ -79,9 +82,9 @@ void main() {
),
);
{
final html.ImageElement img =
controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, html.document)!
as html.ImageElement;
final HTMLImageElement img =
controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, document)!
as HTMLImageElement;
await null; // let `getTile` `then` complete
expect(
img.src,
Expand All @@ -95,10 +98,12 @@ void main() {
tileProvider: TestTileProvider(),
));
{
final html.ImageElement img =
controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, html.document)!
as html.ImageElement;
final HTMLImageElement img =
controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, document)!
as HTMLImageElement;

await img.onLoad.first;

expect(
img.src,
isNotEmpty,
Expand All @@ -109,7 +114,7 @@ void main() {
controller.update(const TileOverlay(tileOverlayId: id));
{
expect(
controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, html.document),
controller.gmMapType.getTile!(gmaps.Point(0, 0), 0, document),
null,
reason: 'Setting a null tileProvider should work.',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:html' as html;

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps/google_maps.dart' as gmaps;
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart'
hide GoogleMapController;
// ignore: implementation_imports
import 'package:google_maps_flutter_web/src/utils.dart';
import 'package:integration_test/integration_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:web/web.dart';

@GenerateNiceMocks(<MockSpec<dynamic>>[MockSpec<TileProvider>()])
import 'overlays_test.mocks.dart';
Expand All @@ -38,13 +40,13 @@ void main() {
/// 0.
void probeTiles() {
for (final gmaps.MapType? mapType in map.overlayMapTypes!.array!) {
mapType?.getTile!(gmaps.Point(0, 0), 0, html.document);
mapType?.getTile!(gmaps.Point(0, 0), 0, document);
}
}

setUp(() {
controller = TileOverlaysController();
map = gmaps.GMap(html.DivElement());
map = gmaps.GMap(createDivElement());
controller.googleMap = map;

tileProviders = <MockTileProvider>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:html' as html;
import 'dart:ui';

import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps/google_maps.dart' as gmaps;
import 'package:google_maps/google_maps_geometry.dart' as geometry;
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
// ignore: implementation_imports
import 'package:google_maps_flutter_web/src/utils.dart';
import 'package:integration_test/integration_test.dart';

// This value is used when comparing the results of
Expand All @@ -25,7 +26,7 @@ void main() {
late gmaps.GMap map;

setUp(() {
map = gmaps.GMap(html.DivElement());
map = gmaps.GMap(createDivElement());
});

group('CirclesController', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return const Text('Testing... Look at the console output for results!');
return const Directionality(
Copy link
Contributor Author

@navaronbracke navaronbracke Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accidentally ran the example app once directly (using flutter run -d chrome) and it did throw an error about a missing Directionality widget

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, the skeleton app is only used to have a Flutter context where things run, but IIRC this particular test does not render a map or anything.

textDirection: TextDirection.ltr,
child: Text('Testing... Look at the console output for results!'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ publish_to: none

# Tests require flutter beta or greater to run.
environment:
sdk: ^3.1.0
flutter: ">=3.13.0"
sdk: ^3.3.0
flutter: ">=3.19.0"

dependencies:
flutter:
sdk: flutter
google_maps_flutter_platform_interface: ^2.4.0
google_maps_flutter_web:
path: ../
web: ^0.5.0

dev_dependencies:
build_runner: ^2.1.1
flutter_test:
sdk: flutter
google_maps: ^6.1.0
google_maps: ^7.1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not blocking for this review, but when I tried to do a Wasm build of the google maps' example app for web, I still get some errors coming from the google_maps package:

  • google_maps-7.1.0
    • lib/src/generated/google_maps_core.js.g.dart:26:8:
      Error: Dart library 'dart:web_gl' is not available on this platform.
    • lib/src/google_maps.dart:15:1: Error: JS interop
      library 'package:js/js.dart' can't be imported when compiling to Wasm.
    • lib/src/google_maps.dart:16:1: Error: JS interop
      library 'package:js/js_util.dart' can't be imported when compiling to Wasm.
  • js_wrapping-0.7.4
    • lib/js_wrapping.dart:9:1: Error: JS interop library
      'package:js/js.dart' can't be imported when compiling to Wasm.
    • lib/js_wrapping.dart:10:1: Error: JS interop library
      'package:js/js_util.dart' can't be imported when compiling to Wasm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we file a tracking issue for google_maps WASM support?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should, compiling to --wasm is the main goal of this migration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/FYI @kevmoo!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah 💩 . Ugh...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google_maps_flutter: ^2.2.0 # Needed for projection_test.dart
http: ">=0.13.0 <2.0.0"
integration_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ library google_maps_flutter_web;

import 'dart:async';
import 'dart:convert';
import 'dart:html' hide VoidCallback;
import 'dart:js_util';
import 'dart:js_interop';
import 'dart:ui_web' as ui_web;

import 'package:collection/collection.dart';
Expand All @@ -20,10 +19,14 @@ import 'package:google_maps/google_maps.dart' as gmaps;
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:sanitize_html/sanitize_html.dart';
import 'package:stream_transform/stream_transform.dart';
import 'package:web/web.dart';

import 'src/dom_window_extension.dart';
import 'src/google_maps_inspector_web.dart';
import 'src/map_styler.dart';
import 'src/third_party/to_screen_location/to_screen_location.dart';
import 'src/types.dart';
import 'src/utils.dart';

part 'src/circle.dart';
part 'src/circles.dart';
Expand Down
Loading