-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[google_maps_flutter_web] Add Advanced markers support (web) #9773
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
Open
aednlaxer
wants to merge
25
commits into
flutter:main
Choose a base branch
from
CodemateLtd:feature/advanced_markers_google_maps_flutter_web
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
94f593b
Add Advanced markers support (web)
aednlaxer bf9ab89
Set minimum version of `web` package to 1.0.0
aednlaxer c2f5cb0
Advanced markers package pr fixes
illuminati1911 ee76359
Unify web package double import
illuminati1911 6c8a158
Raise google maps flutter web package to version 0.6.0
illuminati1911 cf9c3a5
Fix get marker id function in google maps flutter web package
illuminati1911 45b32d3
Updated license headers in the google maps flutter web package
illuminati1911 97b24fd
Minor refactoring to advanced markers for web
illuminati1911 4bae6f9
Handle listeners for web markers
illuminati1911 770f281
Code formatting
illuminati1911 f30050c
Web package html element refactoring
illuminati1911 cf1bf48
Web integration test fixes
illuminati1911 ff2cf6c
General fixes and refactoring
illuminati1911 f255a1f
web advanced marker documentation changes
illuminati1911 98d8d50
formatting changes
illuminati1911 33f1f95
Merge branch 'main' into feature/advanced_markers_google_maps_flutter…
illuminati1911 4d9d914
readme fix
illuminati1911 5aa1549
further readme fixes
illuminati1911 4162635
Merge branch 'main' into feature/advanced_markers_google_maps_flutter…
illuminati1911 e3496b8
integration test fix
illuminati1911 521ae73
flutter analyze fixes
illuminati1911 740eba4
flutter analyze and format fixes for web package
illuminati1911 732d595
integration test fix
illuminati1911 69f740d
update integration test mocks
illuminati1911 276d88b
fix: MarkersController mock
jokerttu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
10 changes: 8 additions & 2 deletions
10
packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 222 additions & 0 deletions
222
...e_maps_flutter/google_maps_flutter_web/example/integration_test/advanced_marker_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
| 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_web/google_maps_flutter_web.dart'; | ||
| import 'package:google_maps_flutter_web/src/utils.dart'; | ||
| import 'package:integration_test/integration_test.dart'; | ||
|
|
||
| /// Test Markers | ||
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| // Since onTap/DragEnd events happen asynchronously, we need to store when the event | ||
| // is fired. We use a completer so the test can wait for the future to be completed. | ||
| late Completer<bool> methodCalledCompleter; | ||
|
|
||
| /// This is the future value of the [methodCalledCompleter]. Reinitialized | ||
| /// in the [setUp] method, and completed (as `true`) by [onTap] and [onDragEnd] | ||
| /// when those methods are called from the MarkerController. | ||
| late Future<bool> methodCalled; | ||
|
|
||
| void onTap() { | ||
| methodCalledCompleter.complete(true); | ||
| } | ||
|
|
||
| void onDragStart(gmaps.LatLng _) { | ||
| methodCalledCompleter.complete(true); | ||
| } | ||
|
|
||
| void onDrag(gmaps.LatLng _) { | ||
| methodCalledCompleter.complete(true); | ||
| } | ||
|
|
||
| void onDragEnd(gmaps.LatLng _) { | ||
| methodCalledCompleter.complete(true); | ||
| } | ||
|
|
||
| setUp(() { | ||
| methodCalledCompleter = Completer<bool>(); | ||
| methodCalled = methodCalledCompleter.future; | ||
| }); | ||
|
|
||
| group('MarkerController', () { | ||
| late gmaps.AdvancedMarkerElement marker; | ||
|
|
||
| setUp(() { | ||
| marker = gmaps.AdvancedMarkerElement(); | ||
| }); | ||
|
|
||
| testWidgets('onTap gets called', (WidgetTester tester) async { | ||
| AdvancedMarkerController(marker: marker, onTap: onTap); | ||
|
|
||
| // Trigger a click event... | ||
| gmaps.event.trigger(marker, 'click', gmaps.MapMouseEvent()); | ||
|
|
||
| // The event handling is now truly async. Wait for it... | ||
| expect(await methodCalled, isTrue); | ||
| }); | ||
|
|
||
| testWidgets('onDragStart gets called', (WidgetTester tester) async { | ||
| AdvancedMarkerController(marker: marker, onDragStart: onDragStart); | ||
|
|
||
| // Trigger a drag end event... | ||
| gmaps.event.trigger( | ||
| marker, | ||
| 'dragstart', | ||
| gmaps.MapMouseEvent()..latLng = gmaps.LatLng(0, 0), | ||
| ); | ||
|
|
||
| expect(await methodCalled, isTrue); | ||
| }); | ||
|
|
||
| testWidgets('onDrag gets called', (WidgetTester tester) async { | ||
| AdvancedMarkerController(marker: marker, onDrag: onDrag); | ||
|
|
||
| // Trigger a drag end event... | ||
| gmaps.event.trigger( | ||
| marker, | ||
| 'drag', | ||
| gmaps.MapMouseEvent()..latLng = gmaps.LatLng(0, 0), | ||
| ); | ||
|
|
||
| expect(await methodCalled, isTrue); | ||
| }); | ||
|
|
||
| testWidgets('onDragEnd gets called', (WidgetTester tester) async { | ||
| AdvancedMarkerController(marker: marker, onDragEnd: onDragEnd); | ||
|
|
||
| // Trigger a drag end event... | ||
| gmaps.event.trigger( | ||
| marker, | ||
| 'dragend', | ||
| gmaps.MapMouseEvent()..latLng = gmaps.LatLng(0, 0), | ||
| ); | ||
|
|
||
| expect(await methodCalled, isTrue); | ||
| }); | ||
|
|
||
| testWidgets('update', (WidgetTester tester) async { | ||
| final controller = AdvancedMarkerController(marker: marker); | ||
| final options = gmaps.AdvancedMarkerElementOptions() | ||
| ..collisionBehavior = | ||
| gmaps.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY | ||
| ..gmpDraggable = true | ||
| ..position = gmaps.LatLng(42, 54); | ||
|
|
||
| expect(marker.collisionBehavior, gmaps.CollisionBehavior.REQUIRED); | ||
| expect(marker.gmpDraggable, isFalse); | ||
|
|
||
| controller.update(options); | ||
|
|
||
| expect(marker.gmpDraggable, isTrue); | ||
| expect( | ||
| marker.collisionBehavior, | ||
| gmaps.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY, | ||
| ); | ||
| final JSAny? position = marker.position; | ||
| expect(position, isNotNull); | ||
| expect(position is gmaps.LatLngLiteral, isTrue); | ||
| expect((position! as gmaps.LatLngLiteral).lat, equals(42)); | ||
| expect((position as gmaps.LatLngLiteral).lng, equals(54)); | ||
| }); | ||
|
|
||
| testWidgets('infoWindow null, showInfoWindow.', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| final controller = AdvancedMarkerController(marker: marker); | ||
|
|
||
| controller.showInfoWindow(); | ||
|
|
||
| expect(controller.infoWindowShown, isFalse); | ||
| }); | ||
|
|
||
| testWidgets('showInfoWindow', (WidgetTester tester) async { | ||
| final infoWindow = gmaps.InfoWindow(); | ||
| final map = gmaps.Map(createDivElement()); | ||
| marker.map = map; | ||
| final controller = AdvancedMarkerController( | ||
| marker: marker, | ||
| infoWindow: infoWindow, | ||
| ); | ||
|
|
||
| controller.showInfoWindow(); | ||
|
|
||
| expect(infoWindow.get('map'), map); | ||
| expect(controller.infoWindowShown, isTrue); | ||
| }); | ||
|
|
||
| testWidgets('hideInfoWindow', (WidgetTester tester) async { | ||
| final infoWindow = gmaps.InfoWindow(); | ||
| final map = gmaps.Map(createDivElement()); | ||
| marker.map = map; | ||
| final controller = AdvancedMarkerController( | ||
| marker: marker, | ||
| infoWindow: infoWindow, | ||
| ); | ||
|
|
||
| controller.hideInfoWindow(); | ||
|
|
||
| expect(infoWindow.get('map'), isNull); | ||
| expect(controller.infoWindowShown, isFalse); | ||
| }); | ||
|
|
||
| group('remove', () { | ||
| late AdvancedMarkerController controller; | ||
|
|
||
| setUp(() { | ||
| final infoWindow = gmaps.InfoWindow(); | ||
| final map = gmaps.Map(createDivElement()); | ||
| marker.map = map; | ||
| controller = AdvancedMarkerController( | ||
| marker: marker, | ||
| infoWindow: infoWindow, | ||
| ); | ||
| }); | ||
|
|
||
| testWidgets('drops gmaps instance', (WidgetTester tester) async { | ||
| controller.remove(); | ||
|
|
||
| expect(controller.marker, isNull); | ||
| }); | ||
|
|
||
| testWidgets('cannot call update after remove', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| final options = gmaps.AdvancedMarkerElementOptions() | ||
| ..gmpDraggable = true; | ||
|
|
||
| controller.remove(); | ||
|
|
||
| expect(() { | ||
| controller.update(options); | ||
| }, throwsAssertionError); | ||
| }); | ||
|
|
||
| testWidgets('cannot call showInfoWindow after remove', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| controller.remove(); | ||
|
|
||
| expect(() { | ||
| controller.showInfoWindow(); | ||
| }, throwsStateError); | ||
| }); | ||
|
|
||
| testWidgets('cannot call hideInfoWindow after remove', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| controller.remove(); | ||
|
|
||
| expect(() { | ||
| controller.hideInfoWindow(); | ||
| }, throwsAssertionError); | ||
| }); | ||
| }); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please list the breaking changes (following repo style), and provide more details about the new APIs, giving someone reading this enough pointers that they could figure out what APIs to go look at to adopt the new markers.