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

Commit 6255da3

Browse files
[google_maps_flutter] Add structure options to platform interface (#5960)
1 parent b5b7027 commit 6255da3

13 files changed

+999
-32
lines changed

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
## NEXT
1+
## 2.2.0
22

3+
* Adds new versions of `buildView` and `updateOptions` that take a new option
4+
class instead of a dictionary, to remove the cross-package dependency on
5+
magic string keys.
6+
* Adopts several parameter objects in the new `buildView` variant to
7+
future-proof it against future changes.
38
* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/104231).
49

510
## 2.1.7

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/method_channel/method_channel_google_maps_flutter.dart

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
1616
import 'package:stream_transform/stream_transform.dart';
1717

1818
import '../types/tile_overlay_updates.dart';
19+
import '../types/utils/map_configuration_serialization.dart';
1920

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

487-
@override
488-
Widget buildViewWithTextDirection(
488+
Widget _buildView(
489489
int creationId,
490490
PlatformViewCreatedCallback onPlatformViewCreated, {
491-
required CameraPosition initialCameraPosition,
492-
required TextDirection textDirection,
493-
Set<Marker> markers = const <Marker>{},
494-
Set<Polygon> polygons = const <Polygon>{},
495-
Set<Polyline> polylines = const <Polyline>{},
496-
Set<Circle> circles = const <Circle>{},
497-
Set<TileOverlay> tileOverlays = const <TileOverlay>{},
498-
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
491+
required MapWidgetConfiguration widgetConfiguration,
492+
MapObjects mapObjects = const MapObjects(),
499493
Map<String, dynamic> mapOptions = const <String, dynamic>{},
500494
}) {
501495
final Map<String, dynamic> creationParams = <String, dynamic>{
502-
'initialCameraPosition': initialCameraPosition.toMap(),
496+
'initialCameraPosition':
497+
widgetConfiguration.initialCameraPosition.toMap(),
503498
'options': mapOptions,
504-
'markersToAdd': serializeMarkerSet(markers),
505-
'polygonsToAdd': serializePolygonSet(polygons),
506-
'polylinesToAdd': serializePolylineSet(polylines),
507-
'circlesToAdd': serializeCircleSet(circles),
508-
'tileOverlaysToAdd': serializeTileOverlaySet(tileOverlays),
499+
'markersToAdd': serializeMarkerSet(mapObjects.markers),
500+
'polygonsToAdd': serializePolygonSet(mapObjects.polygons),
501+
'polylinesToAdd': serializePolylineSet(mapObjects.polylines),
502+
'circlesToAdd': serializeCircleSet(mapObjects.circles),
503+
'tileOverlaysToAdd': serializeTileOverlaySet(mapObjects.tileOverlays),
509504
};
510505

511506
if (defaultTargetPlatform == TargetPlatform.android) {
@@ -518,8 +513,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
518513
) {
519514
return AndroidViewSurface(
520515
controller: controller as AndroidViewController,
521-
gestureRecognizers: gestureRecognizers ??
522-
const <Factory<OneSequenceGestureRecognizer>>{},
516+
gestureRecognizers: widgetConfiguration.gestureRecognizers,
523517
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
524518
);
525519
},
@@ -528,7 +522,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
528522
PlatformViewsService.initSurfaceAndroidView(
529523
id: params.id,
530524
viewType: 'plugins.flutter.io/google_maps',
531-
layoutDirection: textDirection,
525+
layoutDirection: widgetConfiguration.textDirection,
532526
creationParams: creationParams,
533527
creationParamsCodec: const StandardMessageCodec(),
534528
onFocus: () => params.onFocusChanged(true),
@@ -548,7 +542,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
548542
return AndroidView(
549543
viewType: 'plugins.flutter.io/google_maps',
550544
onPlatformViewCreated: onPlatformViewCreated,
551-
gestureRecognizers: gestureRecognizers,
545+
gestureRecognizers: widgetConfiguration.gestureRecognizers,
552546
creationParams: creationParams,
553547
creationParamsCodec: const StandardMessageCodec(),
554548
);
@@ -557,7 +551,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
557551
return UiKitView(
558552
viewType: 'plugins.flutter.io/google_maps',
559553
onPlatformViewCreated: onPlatformViewCreated,
560-
gestureRecognizers: gestureRecognizers,
554+
gestureRecognizers: widgetConfiguration.gestureRecognizers,
561555
creationParams: creationParams,
562556
creationParamsCodec: const StandardMessageCodec(),
563557
);
@@ -567,6 +561,53 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
567561
'$defaultTargetPlatform is not yet supported by the maps plugin');
568562
}
569563

564+
@override
565+
Widget buildViewWithConfiguration(
566+
int creationId,
567+
PlatformViewCreatedCallback onPlatformViewCreated, {
568+
required MapWidgetConfiguration widgetConfiguration,
569+
MapConfiguration mapConfiguration = const MapConfiguration(),
570+
MapObjects mapObjects = const MapObjects(),
571+
}) {
572+
return _buildView(
573+
creationId,
574+
onPlatformViewCreated,
575+
widgetConfiguration: widgetConfiguration,
576+
mapObjects: mapObjects,
577+
mapOptions: jsonForMapConfiguration(mapConfiguration),
578+
);
579+
}
580+
581+
@override
582+
Widget buildViewWithTextDirection(
583+
int creationId,
584+
PlatformViewCreatedCallback onPlatformViewCreated, {
585+
required CameraPosition initialCameraPosition,
586+
required TextDirection textDirection,
587+
Set<Marker> markers = const <Marker>{},
588+
Set<Polygon> polygons = const <Polygon>{},
589+
Set<Polyline> polylines = const <Polyline>{},
590+
Set<Circle> circles = const <Circle>{},
591+
Set<TileOverlay> tileOverlays = const <TileOverlay>{},
592+
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
593+
Map<String, dynamic> mapOptions = const <String, dynamic>{},
594+
}) {
595+
return _buildView(
596+
creationId,
597+
onPlatformViewCreated,
598+
widgetConfiguration: MapWidgetConfiguration(
599+
initialCameraPosition: initialCameraPosition,
600+
textDirection: textDirection),
601+
mapObjects: MapObjects(
602+
markers: markers,
603+
polygons: polygons,
604+
polylines: polylines,
605+
circles: circles,
606+
tileOverlays: tileOverlays),
607+
mapOptions: mapOptions,
608+
);
609+
}
610+
570611
@override
571612
Widget buildView(
572613
int creationId,

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:flutter/material.dart';
1313
import 'package:flutter/services.dart';
1414
import 'package:flutter/widgets.dart';
1515
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
16+
import 'package:google_maps_flutter_platform_interface/src/types/utils/map_configuration_serialization.dart';
1617
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
1718

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

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

68+
/// Updates configuration options of the map user interface.
69+
///
70+
/// Change listeners are notified once the update has been made on the
71+
/// platform side.
72+
///
73+
/// The returned [Future] completes after listeners have been notified.
74+
Future<void> updateMapConfiguration(
75+
MapConfiguration configuration, {
76+
required int mapId,
77+
}) {
78+
return updateMapOptions(jsonForMapConfiguration(configuration),
79+
mapId: mapId);
80+
}
81+
6682
/// Updates marker configuration.
6783
///
6884
/// Change listeners are notified once the update has been made on the
@@ -348,7 +364,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
348364
throw UnimplementedError('dispose() has not been implemented.');
349365
}
350366

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

370-
/// Returns a widget displaying the map view.
387+
/// Returns a widget displaying the map view - deprecated, use
388+
/// [buildViewWithConfiguration] instead.
371389
///
372390
/// This method is similar to [buildView], but contains a parameter for
373391
/// platforms that require a text direction.
@@ -381,12 +399,12 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
381399
PlatformViewCreatedCallback onPlatformViewCreated, {
382400
required CameraPosition initialCameraPosition,
383401
required TextDirection textDirection,
402+
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
384403
Set<Marker> markers = const <Marker>{},
385404
Set<Polygon> polygons = const <Polygon>{},
386405
Set<Polyline> polylines = const <Polyline>{},
387406
Set<Circle> circles = const <Circle>{},
388407
Set<TileOverlay> tileOverlays = const <TileOverlay>{},
389-
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
390408
Map<String, dynamic> mapOptions = const <String, dynamic>{},
391409
}) {
392410
return buildView(
@@ -402,4 +420,27 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
402420
mapOptions: mapOptions,
403421
);
404422
}
423+
424+
/// Returns a widget displaying the map view.
425+
Widget buildViewWithConfiguration(
426+
int creationId,
427+
PlatformViewCreatedCallback onPlatformViewCreated, {
428+
required MapWidgetConfiguration widgetConfiguration,
429+
MapConfiguration mapConfiguration = const MapConfiguration(),
430+
MapObjects mapObjects = const MapObjects(),
431+
}) {
432+
return buildViewWithTextDirection(
433+
creationId,
434+
onPlatformViewCreated,
435+
initialCameraPosition: widgetConfiguration.initialCameraPosition,
436+
textDirection: widgetConfiguration.textDirection,
437+
markers: mapObjects.markers,
438+
polygons: mapObjects.polygons,
439+
polylines: mapObjects.polylines,
440+
circles: mapObjects.circles,
441+
tileOverlays: mapObjects.tileOverlays,
442+
gestureRecognizers: widgetConfiguration.gestureRecognizers,
443+
mapOptions: jsonForMapConfiguration(mapConfiguration),
444+
);
445+
}
405446
}

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ class BitmapDescriptor {
1818
const BitmapDescriptor._(this._json);
1919

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

0 commit comments

Comments
 (0)