Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -32,3 +32,8 @@ flutter:
uses-material-design: true
assets:
- assets/
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
google_maps_flutter_platform_interface: {path: /Users/zubii/Projects/packages/packages/google_maps_flutter/google_maps_flutter_platform_interface}
google_maps_flutter_web: {path: ../../../../packages/google_maps_flutter/google_maps_flutter_web}
6 changes: 6 additions & 0 deletions packages/google_maps_flutter/google_maps_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ topics:
# The example deliberately includes limited-use secrets.
false_secrets:
- /example/web/index.html

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
google_maps_flutter_platform_interface: {path: /Users/zubii/Projects/packages/packages/google_maps_flutter/google_maps_flutter_platform_interface}
google_maps_flutter_web: {path: ../../../packages/google_maps_flutter/google_maps_flutter_web}
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ Alex Li <google@alexv525.com>
Rahul Raj <64.rahulraj@gmail.com>
Justin Baumann <me@jxstxn.dev>
Joonas Kerttula <joonas.kerttula@codemate.com>
Zubsacu Ionut <ionutzubascu12@gmail.com>
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.3

* Add support for my location button.

## 0.6.2+3

* Updates README to include setup information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ The following map options are not available in web, because the map doesn't rota

There's no "Map Toolbar" in web, so the `mapToolbarEnabled` option is unused.

There's no "My Location" widget in web ([tracking issue](https://github.com/flutter/flutter/issues/64073)), so the following options are ignored, for now:

* `myLocationButtonEnabled`
* `myLocationEnabled`

There's no `defaultMarkerWithHue` in web. If you need colored pins/markers, you may need to use your own asset images.

Indoor and building layers are still not available on the web. Traffic is.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ gmaps.Map mapShim() => throw UnimplementedError();
),
MockSpec<TileOverlaysController>(fallbackGenerators: <Symbol, Function>{#googleMap: mapShim}),
MockSpec<GroundOverlaysController>(fallbackGenerators: <Symbol, Function>{#googleMap: mapShim}),
MockSpec<MyLocationController>(fallbackGenerators: <Symbol, Function>{#googleMap: mapShim}),
MockSpec<GeolocationApi>(fallbackGenerators: <Symbol, Function>{#googleMap: mapShim}),
])
/// Test Google Map Controller
void main() {
Expand Down Expand Up @@ -1025,5 +1027,121 @@ void main() {
verify(mock.isInfoWindowShown(markerId));
});
});

group('My Location', () {
late MockMyLocationController mockMyLocationController;
late MockGeolocationApi mockGeolocationApi;

setUp(() {
mockMyLocationController = MockMyLocationController();
mockGeolocationApi = MockGeolocationApi();
});

testWidgets('by default is disabled', (WidgetTester tester) async {
controller = createController();
controller.init();
expect(mockMyLocationController.myLocationButton, isNull);
});

testWidgets('initializes with my location & display my location button', (
WidgetTester tester,
) async {
const currentLocation = LatLng(10.8231, 106.6297);
final map = gmaps.Map(createDivElement());
final markers = MockMarkersController();

controller = createController(
mapConfiguration: const MapConfiguration(
myLocationEnabled: true,
myLocationButtonEnabled: true,
),
);

final myLocationController = MyLocationController(geolocationApi: mockGeolocationApi);

controller.debugSetOverrides(
createMap: (_, _) => map,
markers: markers,
myLocation: myLocationController,
);

when(mockGeolocationApi.watchPosition(any, any)).thenAnswer((inv) {
final onSuccess = inv.positionalArguments[0] as void Function(double, double);
onSuccess(currentLocation.latitude, currentLocation.longitude);
return 0;
});
when(
mockGeolocationApi.getCurrentPosition(any, any, timeoutMs: anyNamed('timeoutMs')),
).thenAnswer((inv) {
final onSuccess = inv.positionalArguments[0] as void Function(double, double);
onSuccess(currentLocation.latitude, currentLocation.longitude);
});

controller.init();
await tester.pumpAndSettle();

final List<Set<Marker>> allAddMarkersCalls = verify(
markers.addMarkers(captureAny),
).captured.cast<Set<Marker>>();
final Set<Marker> blueDotCall = allAddMarkersCalls.firstWhere(
(set) => set.any((m) => m.markerId == const MarkerId('my_location_blue_dot')),
orElse: () => <Marker>{},
);

expect(blueDotCall.length, 1);
expect(blueDotCall.first.position, currentLocation);
expect(blueDotCall.first.zIndex, .5);
expect(map.controls[gmaps.ControlPosition.RIGHT_BOTTOM as int].length, equals(1));
});

testWidgets('initializes with my location only', (WidgetTester tester) async {
final map = gmaps.Map(createDivElement());
final markers = MockMarkersController();
const currentLocation = LatLng(10.8231, 106.6297);

controller = createController(
mapConfiguration: const MapConfiguration(
myLocationEnabled: true,
myLocationButtonEnabled: false,
),
);

final myLocationController = MyLocationController(geolocationApi: mockGeolocationApi);

controller.debugSetOverrides(
createMap: (_, _) => map,
markers: markers,
myLocation: myLocationController,
);

when(mockGeolocationApi.watchPosition(any, any)).thenAnswer((inv) {
final onSuccess = inv.positionalArguments[0] as void Function(double, double);
onSuccess(currentLocation.latitude, currentLocation.longitude);
return 0;
});
when(
mockGeolocationApi.getCurrentPosition(any, any, timeoutMs: anyNamed('timeoutMs')),
).thenAnswer((inv) {
final onSuccess = inv.positionalArguments[0] as void Function(double, double);
onSuccess(currentLocation.latitude, currentLocation.longitude);
});

controller.init();
await tester.pumpAndSettle();

final List<Set<Marker>> allAddMarkersCalls = verify(
markers.addMarkers(captureAny),
).captured.cast<Set<Marker>>();
final Set<Marker> blueDotCall = allAddMarkersCalls.firstWhere(
(set) => set.any((m) => m.markerId == const MarkerId('my_location_blue_dot')),
orElse: () => <Marker>{},
);

expect(blueDotCall.length, 1);
expect(blueDotCall.first.position, currentLocation);
expect(blueDotCall.first.zIndex, 0.5);
expect(map.controls[gmaps.ControlPosition.RIGHT_BOTTOM as int].length, equals(0));
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,87 @@ class MockGroundOverlaysController extends _i1.Mock implements _i2.GroundOverlay
returnValueForMissingStub: null,
);
}

/// A class which mocks [MyLocationController].
///
/// See the documentation for Mockito's code generation for more information.
class MockMyLocationController extends _i1.Mock implements _i2.MyLocationController {
@override
set myLocationButton(_i2.MyLocationButton? value) => super.noSuchMethod(
Invocation.setter(#myLocationButton, value),
returnValueForMissingStub: null,
);

@override
_i6.Future<void> displayAndWatchMyLocation(
_i2.MarkersController<Object?, Object>? markersController,
) =>
(super.noSuchMethod(
Invocation.method(#displayAndWatchMyLocation, [markersController]),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
)
as _i6.Future<void>);

@override
_i6.Future<void> centerMyCurrentLocation(_i2.GoogleMapController? controller) =>
(super.noSuchMethod(
Invocation.method(#centerMyCurrentLocation, [controller]),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
)
as _i6.Future<void>);

@override
void addMyLocationButton(_i4.Map? map, _i2.GoogleMapController? controller) => super.noSuchMethod(
Invocation.method(#addMyLocationButton, [map, controller]),
returnValueForMissingStub: null,
);

@override
void removeMyLocationButton(_i4.Map? map) => super.noSuchMethod(
Invocation.method(#removeMyLocationButton, [map]),
returnValueForMissingStub: null,
);

@override
void removeBlueDot(_i2.MarkersController<Object?, Object?>? markersController) =>
super.noSuchMethod(
Invocation.method(#removeBlueDot, [markersController]),
returnValueForMissingStub: null,
);

@override
void dispose() =>
super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null);
}

/// A class which mocks [GeolocationApi].
///
/// See the documentation for Mockito's code generation for more information.
class MockGeolocationApi extends _i1.Mock implements _i2.GeolocationApi {
@override
int watchPosition(void Function(double, double)? onSuccess, void Function(dynamic)? onError) =>
(super.noSuchMethod(
Invocation.method(#watchPosition, [onSuccess, onError]),
returnValue: 0,
returnValueForMissingStub: 0,
)
as int);

@override
void getCurrentPosition(
void Function(double, double)? onSuccess,
void Function(dynamic)? onError, {
int? timeoutMs = 30000,
}) => super.noSuchMethod(
Invocation.method(#getCurrentPosition, [onSuccess, onError], {#timeoutMs: timeoutMs}),
returnValueForMissingStub: null,
);

@override
void clearWatch(int? watchId) => super.noSuchMethod(
Invocation.method(#clearWatch, [watchId]),
returnValueForMissingStub: null,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import 'package:integration_test/integration_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';

@GenerateNiceMocks(<MockSpec<dynamic>>[MockSpec<GoogleMapController>()])
@GenerateNiceMocks(<MockSpec<dynamic>>[
MockSpec<GoogleMapController>(),
MockSpec<MyLocationController>(),
])
import 'google_maps_plugin_test.mocks.dart';

/// Test GoogleMapsPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class MockGoogleMapController extends _i1.Mock implements _i4.GoogleMapControlle
_i6.ClusterManagersController<Object?>? clusterManagers,
_i4.TileOverlaysController? tileOverlays,
_i4.GroundOverlaysController? groundOverlays,
_i4.MyLocationController? myLocation,
}) => super.noSuchMethod(
Invocation.method(#debugSetOverrides, [], {
#createMap: createMap,
Expand All @@ -132,6 +133,7 @@ class MockGoogleMapController extends _i1.Mock implements _i4.GoogleMapControlle
#clusterManagers: clusterManagers,
#tileOverlays: tileOverlays,
#groundOverlays: groundOverlays,
#myLocation: myLocation,
}),
returnValueForMissingStub: null,
);
Expand Down Expand Up @@ -297,3 +299,57 @@ class MockGoogleMapController extends _i1.Mock implements _i4.GoogleMapControlle
void dispose() =>
super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null);
}

/// A class which mocks [MyLocationController].
///
/// See the documentation for Mockito's code generation for more information.
class MockMyLocationController extends _i1.Mock implements _i4.MyLocationController {
@override
set myLocationButton(_i4.MyLocationButton? value) => super.noSuchMethod(
Invocation.setter(#myLocationButton, value),
returnValueForMissingStub: null,
);

@override
_i3.Future<void> displayAndWatchMyLocation(
_i4.MarkersController<Object?, Object>? markersController,
) =>
(super.noSuchMethod(
Invocation.method(#displayAndWatchMyLocation, [markersController]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);

@override
_i3.Future<void> centerMyCurrentLocation(_i4.GoogleMapController? controller) =>
(super.noSuchMethod(
Invocation.method(#centerMyCurrentLocation, [controller]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);

@override
void addMyLocationButton(_i5.Map? map, _i4.GoogleMapController? controller) => super.noSuchMethod(
Invocation.method(#addMyLocationButton, [map, controller]),
returnValueForMissingStub: null,
);

@override
void removeMyLocationButton(_i5.Map? map) => super.noSuchMethod(
Invocation.method(#removeMyLocationButton, [map]),
returnValueForMissingStub: null,
);

@override
void removeBlueDot(_i4.MarkersController<Object?, Object?>? markersController) =>
super.noSuchMethod(
Invocation.method(#removeBlueDot, [markersController]),
returnValueForMissingStub: null,
);

@override
void dispose() =>
super.noSuchMethod(Invocation.method(#dispose, []), returnValueForMissingStub: null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ flutter:
assets:
- assets/

# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
google_maps_flutter:
{ path: ../../../../../packages/google_maps_flutter/google_maps_flutter }
# Override the google_maps_flutter dependency on google_maps_flutter_web.
# TODO(ditman): Unwind the circular dependency. This will create problems
# if we need to make a breaking change to google_maps_flutter_web.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import 'src/utils.dart';
part 'src/circle.dart';
part 'src/circles.dart';
part 'src/convert.dart';
part 'src/geolocation_api.dart';
part 'src/google_maps_controller.dart';
part 'src/google_maps_flutter_web.dart';
part 'src/ground_overlay.dart';
Expand All @@ -41,6 +42,7 @@ part 'src/heatmap.dart';
part 'src/heatmaps.dart';
part 'src/marker.dart';
part 'src/markers.dart';
part 'src/my_location.dart';
part 'src/overlay.dart';
part 'src/overlays.dart';
part 'src/polygon.dart';
Expand Down
Loading