Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter] Add structure options to platform interface #5960

Merged
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
@@ -1,5 +1,10 @@
## NEXT
## 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.
* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/104231).

## 2.1.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
import 'package:stream_transform/stream_transform.dart';

import '../types/tile_overlay_updates.dart';
import '../types/utils/map_configuration_serialization.dart';

/// Error thrown when an unknown map ID is provided to a method channel API.
class UnknownMapIDError extends Error {
Expand Down Expand Up @@ -484,28 +485,22 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
/// Defaults to false.
bool useAndroidViewSurface = false;

@override
Widget buildViewWithTextDirection(
Widget _buildView(
int creationId,
PlatformViewCreatedCallback onPlatformViewCreated, {
required CameraPosition initialCameraPosition,
required TextDirection textDirection,
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,
required MapWidgetConfiguration widgetConfiguration,
MapObjects mapObjects = const MapObjects(),
Map<String, dynamic> mapOptions = const <String, dynamic>{},
}) {
final Map<String, dynamic> creationParams = <String, dynamic>{
'initialCameraPosition': initialCameraPosition.toMap(),
'initialCameraPosition':
widgetConfiguration.initialCameraPosition.toMap(),
'options': mapOptions,
'markersToAdd': serializeMarkerSet(markers),
'polygonsToAdd': serializePolygonSet(polygons),
'polylinesToAdd': serializePolylineSet(polylines),
'circlesToAdd': serializeCircleSet(circles),
'tileOverlaysToAdd': serializeTileOverlaySet(tileOverlays),
'markersToAdd': serializeMarkerSet(mapObjects.markers),
'polygonsToAdd': serializePolygonSet(mapObjects.polygons),
'polylinesToAdd': serializePolylineSet(mapObjects.polylines),
'circlesToAdd': serializeCircleSet(mapObjects.circles),
'tileOverlaysToAdd': serializeTileOverlaySet(mapObjects.tileOverlays),
};

if (defaultTargetPlatform == TargetPlatform.android) {
Expand All @@ -518,8 +513,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
gestureRecognizers: gestureRecognizers ??
const <Factory<OneSequenceGestureRecognizer>>{},
gestureRecognizers: widgetConfiguration.gestureRecognizers,
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
);
},
Expand All @@ -528,7 +522,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
PlatformViewsService.initSurfaceAndroidView(
id: params.id,
viewType: 'plugins.flutter.io/google_maps',
layoutDirection: textDirection,
layoutDirection: widgetConfiguration.textDirection,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
onFocus: () => params.onFocusChanged(true),
Expand All @@ -548,7 +542,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
return AndroidView(
viewType: 'plugins.flutter.io/google_maps',
onPlatformViewCreated: onPlatformViewCreated,
gestureRecognizers: gestureRecognizers,
gestureRecognizers: widgetConfiguration.gestureRecognizers,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
);
Expand All @@ -557,7 +551,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
return UiKitView(
viewType: 'plugins.flutter.io/google_maps',
onPlatformViewCreated: onPlatformViewCreated,
gestureRecognizers: gestureRecognizers,
gestureRecognizers: widgetConfiguration.gestureRecognizers,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
);
Expand All @@ -567,6 +561,53 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
'$defaultTargetPlatform is not yet supported by the maps plugin');
}

@override
Widget buildViewWithConfiguration(
int creationId,
PlatformViewCreatedCallback onPlatformViewCreated, {
required MapWidgetConfiguration widgetConfiguration,
MapConfiguration mapConfiguration = const MapConfiguration(),
MapObjects mapObjects = const MapObjects(),
}) {
return _buildView(
creationId,
onPlatformViewCreated,
widgetConfiguration: widgetConfiguration,
mapObjects: mapObjects,
mapOptions: jsonForMapConfiguration(mapConfiguration),
);
}

@override
Widget buildViewWithTextDirection(
int creationId,
PlatformViewCreatedCallback onPlatformViewCreated, {
required CameraPosition initialCameraPosition,
required TextDirection textDirection,
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,
Map<String, dynamic> mapOptions = const <String, dynamic>{},
}) {
return _buildView(
creationId,
onPlatformViewCreated,
widgetConfiguration: MapWidgetConfiguration(
initialCameraPosition: initialCameraPosition,
textDirection: textDirection),
mapObjects: MapObjects(
markers: markers,
polygons: polygons,
polylines: polylines,
circles: circles,
tileOverlays: tileOverlays),
mapOptions: mapOptions,
);
}

@override
Widget buildView(
int creationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:google_maps_flutter_platform_interface/src/types/utils/map_configuration_serialization.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

/// The interface that platform-specific implementations of `google_maps_flutter` must extend.
Expand Down Expand Up @@ -50,7 +51,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
throw UnimplementedError('init() has not been implemented.');
}

/// Updates configuration options of the map user interface.
/// Updates configuration options of the map user interface - deprecated, use
/// updateMapConfiguration instead.
///
/// Change listeners are notified once the update has been made on the
/// platform side.
Expand All @@ -63,6 +65,20 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
throw UnimplementedError('updateMapOptions() has not been implemented.');
}

/// Updates configuration options of the map user interface.
///
/// Change listeners are notified once the update has been made on the
/// platform side.
///
/// The returned [Future] completes after listeners have been notified.
Future<void> updateMapConfiguration(
MapConfiguration configuration, {
required int mapId,
}) {
return updateMapOptions(jsonForMapConfiguration(configuration),
mapId: mapId);
}

/// Updates marker configuration.
///
/// Change listeners are notified once the update has been made on the
Expand Down Expand Up @@ -348,7 +364,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
throw UnimplementedError('dispose() has not been implemented.');
}

/// Returns a widget displaying the map view.
/// Returns a widget displaying the map view - deprecated, use
/// [buildViewWithConfiguration] instead.
Widget buildView(
int creationId,
PlatformViewCreatedCallback onPlatformViewCreated, {
Expand All @@ -367,7 +384,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
throw UnimplementedError('buildView() has not been implemented.');
}

/// Returns a widget displaying the map view.
/// Returns a widget displaying the map view - deprecated, use
/// [buildViewWithConfiguration] instead.
///
/// This method is similar to [buildView], but contains a parameter for
/// platforms that require a text direction.
Expand All @@ -381,12 +399,12 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
PlatformViewCreatedCallback onPlatformViewCreated, {
required CameraPosition initialCameraPosition,
required TextDirection textDirection,
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
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,
Map<String, dynamic> mapOptions = const <String, dynamic>{},
}) {
return buildView(
Expand All @@ -402,4 +420,27 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
mapOptions: mapOptions,
);
}

/// Returns a widget displaying the map view.
Widget buildViewWithConfiguration(
int creationId,
PlatformViewCreatedCallback onPlatformViewCreated, {
required MapWidgetConfiguration widgetConfiguration,
MapConfiguration mapConfiguration = const MapConfiguration(),
MapObjects mapObjects = const MapObjects(),
}) {
return buildViewWithTextDirection(
creationId,
onPlatformViewCreated,
initialCameraPosition: widgetConfiguration.initialCameraPosition,
textDirection: widgetConfiguration.textDirection,
markers: mapObjects.markers,
polygons: mapObjects.polygons,
polylines: mapObjects.polylines,
circles: mapObjects.circles,
tileOverlays: mapObjects.tileOverlays,
gestureRecognizers: widgetConfiguration.gestureRecognizers,
mapOptions: jsonForMapConfiguration(mapConfiguration),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ class BitmapDescriptor {
const BitmapDescriptor._(this._json);

/// The inverse of .toJson.
// This is needed in Web to re-hydrate BitmapDescriptors that have been
// transformed to JSON for transport.
// TODO(stuartmorgan): Clean this up. See
// https://github.com/flutter/flutter/issues/70330
// TODO(stuartmorgan): Remove this in the next breaking change.
@Deprecated('No longer supported')
BitmapDescriptor.fromJson(Object json) : _json = json {
assert(_json is List<dynamic>);
final List<dynamic> jsonList = json as List<dynamic>;
Expand Down
Loading