Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 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
@@ -1,5 +1,7 @@
## NEXT
## 2.1.6

* Switches to new platform interface versions of `buildView` and
`updateOptions`, making it compatible with `google_maps_flutter_web` 0.4.0.
* Fixes iOS native unit tests on M1 devices.
* Minor fixes for new analysis options.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ class GoogleMapController {
/// platform side.
///
/// The returned [Future] completes after listeners have been notified.
Future<void> _updateMapOptions(Map<String, dynamic> optionsUpdate) {
assert(optionsUpdate != null);
Future<void> _updateMapConfiguration(MapConfiguration update) {
return GoogleMapsFlutterPlatform.instance
.updateMapOptions(optionsUpdate, mapId: mapId);
.updateMapConfiguration(update, mapId: mapId);
}

/// Updates marker configuration.
Expand Down
156 changes: 44 additions & 112 deletions packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,30 +294,34 @@ class _GoogleMapState extends State<GoogleMap> {
Map<PolygonId, Polygon> _polygons = <PolygonId, Polygon>{};
Map<PolylineId, Polyline> _polylines = <PolylineId, Polyline>{};
Map<CircleId, Circle> _circles = <CircleId, Circle>{};
late _GoogleMapOptions _googleMapOptions;
late MapConfiguration _mapConfiguration;

@override
Widget build(BuildContext context) {
return GoogleMapsFlutterPlatform.instance.buildViewWithTextDirection(
return GoogleMapsFlutterPlatform.instance.buildViewWithConfiguration(
_mapId,
onPlatformViewCreated,
textDirection: widget.layoutDirection ??
Directionality.maybeOf(context) ??
TextDirection.ltr,
initialCameraPosition: widget.initialCameraPosition,
markers: widget.markers,
polygons: widget.polygons,
polylines: widget.polylines,
circles: widget.circles,
gestureRecognizers: widget.gestureRecognizers,
mapOptions: _googleMapOptions.toMap(),
widgetConfiguration: MapWidgetConfiguration(
textDirection: widget.layoutDirection ??
Directionality.maybeOf(context) ??
TextDirection.ltr,
initialCameraPosition: widget.initialCameraPosition,
gestureRecognizers: widget.gestureRecognizers,
),
mapObjects: MapObjects(
markers: widget.markers,
polygons: widget.polygons,
polylines: widget.polylines,
circles: widget.circles,
),
mapConfiguration: _mapConfiguration,
);
}

@override
void initState() {
super.initState();
_googleMapOptions = _GoogleMapOptions.fromWidget(widget);
_mapConfiguration = _configurationFromMapWidget(widget);
_markers = keyByMarkerId(widget.markers);
_polygons = keyByPolygonId(widget.polygons);
_polylines = keyByPolylineId(widget.polylines);
Expand Down Expand Up @@ -347,16 +351,15 @@ class _GoogleMapState extends State<GoogleMap> {
}

Future<void> _updateOptions() async {
final _GoogleMapOptions newOptions = _GoogleMapOptions.fromWidget(widget);
final Map<String, dynamic> updates =
_googleMapOptions.updatesMap(newOptions);
final MapConfiguration newConfig = _configurationFromMapWidget(widget);
final MapConfiguration updates = newConfig.diffFrom(_mapConfiguration);
if (updates.isEmpty) {
return;
}
final GoogleMapController controller = await _controller.future;
// ignore: unawaited_futures
controller._updateMapOptions(updates);
_googleMapOptions = newOptions;
controller._updateMapConfiguration(updates);
_mapConfiguration = newConfig;
}

Future<void> _updateMarkers() async {
Expand Down Expand Up @@ -524,98 +527,27 @@ class _GoogleMapState extends State<GoogleMap> {
}
}

/// Configuration options for the GoogleMaps user interface.
class _GoogleMapOptions {
_GoogleMapOptions.fromWidget(GoogleMap map)
: compassEnabled = map.compassEnabled,
mapToolbarEnabled = map.mapToolbarEnabled,
cameraTargetBounds = map.cameraTargetBounds,
mapType = map.mapType,
minMaxZoomPreference = map.minMaxZoomPreference,
rotateGesturesEnabled = map.rotateGesturesEnabled,
scrollGesturesEnabled = map.scrollGesturesEnabled,
tiltGesturesEnabled = map.tiltGesturesEnabled,
trackCameraPosition = map.onCameraMove != null,
zoomControlsEnabled = map.zoomControlsEnabled,
zoomGesturesEnabled = map.zoomGesturesEnabled,
liteModeEnabled = map.liteModeEnabled,
myLocationEnabled = map.myLocationEnabled,
myLocationButtonEnabled = map.myLocationButtonEnabled,
padding = map.padding,
indoorViewEnabled = map.indoorViewEnabled,
trafficEnabled = map.trafficEnabled,
buildingsEnabled = map.buildingsEnabled,
assert(!map.liteModeEnabled || Platform.isAndroid);

final bool compassEnabled;

final bool mapToolbarEnabled;

final CameraTargetBounds cameraTargetBounds;

final MapType mapType;

final MinMaxZoomPreference minMaxZoomPreference;

final bool rotateGesturesEnabled;

final bool scrollGesturesEnabled;

final bool tiltGesturesEnabled;

final bool trackCameraPosition;

final bool zoomControlsEnabled;

final bool zoomGesturesEnabled;

final bool liteModeEnabled;

final bool myLocationEnabled;

final bool myLocationButtonEnabled;

final EdgeInsets padding;

final bool indoorViewEnabled;

final bool trafficEnabled;

final bool buildingsEnabled;

Map<String, dynamic> toMap() {
return <String, dynamic>{
'compassEnabled': compassEnabled,
'mapToolbarEnabled': mapToolbarEnabled,
'cameraTargetBounds': cameraTargetBounds.toJson(),
'mapType': mapType.index,
'minMaxZoomPreference': minMaxZoomPreference.toJson(),
'rotateGesturesEnabled': rotateGesturesEnabled,
'scrollGesturesEnabled': scrollGesturesEnabled,
'tiltGesturesEnabled': tiltGesturesEnabled,
'zoomControlsEnabled': zoomControlsEnabled,
'zoomGesturesEnabled': zoomGesturesEnabled,
'liteModeEnabled': liteModeEnabled,
'trackCameraPosition': trackCameraPosition,
'myLocationEnabled': myLocationEnabled,
'myLocationButtonEnabled': myLocationButtonEnabled,
'padding': <double>[
padding.top,
padding.left,
padding.bottom,
padding.right,
],
'indoorEnabled': indoorViewEnabled,
'trafficEnabled': trafficEnabled,
'buildingsEnabled': buildingsEnabled,
};
}

Map<String, dynamic> updatesMap(_GoogleMapOptions newOptions) {
final Map<String, dynamic> prevOptionsMap = toMap();

return newOptions.toMap()
..removeWhere(
(String key, dynamic value) => prevOptionsMap[key] == value);
}
/// Builds a [MapConfiguration] from the given [map].
MapConfiguration _configurationFromMapWidget(GoogleMap map) {
assert(!map.liteModeEnabled || Platform.isAndroid);
return MapConfiguration(
compassEnabled: map.compassEnabled,
mapToolbarEnabled: map.mapToolbarEnabled,
cameraTargetBounds: map.cameraTargetBounds,
mapType: map.mapType,
minMaxZoomPreference: map.minMaxZoomPreference,
rotateGesturesEnabled: map.rotateGesturesEnabled,
scrollGesturesEnabled: map.scrollGesturesEnabled,
tiltGesturesEnabled: map.tiltGesturesEnabled,
trackCameraPosition: map.onCameraMove != null,
zoomControlsEnabled: map.zoomControlsEnabled,
zoomGesturesEnabled: map.zoomGesturesEnabled,
liteModeEnabled: map.liteModeEnabled,
myLocationEnabled: map.myLocationEnabled,
myLocationButtonEnabled: map.myLocationButtonEnabled,
padding: map.padding,
indoorViewEnabled: map.indoorViewEnabled,
trafficEnabled: map.trafficEnabled,
buildingsEnabled: map.buildingsEnabled,
);
}
10 changes: 8 additions & 2 deletions packages/google_maps_flutter/google_maps_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
repository: https://github.com/flutter/plugins/tree/main/packages/google_maps_flutter/google_maps_flutter
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 2.1.5
version: 2.1.6

environment:
sdk: ">=2.14.0 <3.0.0"
Expand All @@ -21,7 +21,7 @@ dependencies:
flutter:
sdk: flutter
flutter_plugin_android_lifecycle: ^2.0.1
google_maps_flutter_platform_interface: ^2.1.2
google_maps_flutter_platform_interface: ^2.1.2 # 2.2.0

dev_dependencies:
flutter_test:
Expand All @@ -30,3 +30,9 @@ dev_dependencies:
pedantic: ^1.10.0
plugin_platform_interface: ^2.0.0
stream_transform: ^2.0.0


# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
google_maps_flutter_platform_interface:
path: ../../google_maps_flutter/google_maps_flutter_platform_interface
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import 'dart:async';
import 'dart:typed_data';

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -88,8 +86,8 @@ class TestGoogleMapsFlutterPlatform extends GoogleMapsFlutterPlatform {
Future<void> init(int mapId) async {}

@override
Future<void> updateMapOptions(
Map<String, dynamic> optionsUpdate, {
Future<void> updateMapConfiguration(
MapConfiguration update, {
required int mapId,
}) async {}

Expand Down Expand Up @@ -276,18 +274,12 @@ class TestGoogleMapsFlutterPlatform extends GoogleMapsFlutterPlatform {
}

@override
Widget buildView(
Widget buildViewWithConfiguration(
int creationId,
PlatformViewCreatedCallback onPlatformViewCreated, {
required CameraPosition initialCameraPosition,
Set<Marker> markers = const <Marker>{},
Set<Polygon> polygons = const <Polygon>{},
Set<Polyline> polylines = const <Polyline>{},
Set<Circle> circles = const <Circle>{},
Set<TileOverlay> tileOverlays = const <TileOverlay>{},
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers =
const <Factory<OneSequenceGestureRecognizer>>{},
Map<String, dynamic> mapOptions = const <String, dynamic>{},
required MapWidgetConfiguration widgetConfiguration,
MapObjects mapObjects = const MapObjects(),
MapConfiguration mapConfiguration = const MapConfiguration(),
}) {
onPlatformViewCreated(0);
createdIds.add(creationId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.2.0

* Adds new versions of `buildView` and `updateOptions` that take a new option
class instead of a dictionary, to remove the cross-package dependency on
magic string keys.
* Adopts several parameter objects in the new `buildView` variant to
future-proof it against future changes.

## 2.1.7

* Updates code for stricter analysis options.
Expand Down
Loading