Skip to content

Commit 5cb9145

Browse files
stuartmorgan-gmauricioluz
authored andcommitted
[google_maps_flutter] Add structure options to platform interface (flutter#5960)
1 parent f8596cc commit 5cb9145

File tree

13 files changed

+999
-32
lines changed

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 {
@@ -507,18 +508,11 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
507508
/// Defaults to false.
508509
bool useAndroidViewSurface = false;
509510

510-
@override
511-
Widget buildViewWithTextDirection(
511+
Widget _buildView(
512512
int creationId,
513513
PlatformViewCreatedCallback onPlatformViewCreated, {
514-
required CameraPosition initialCameraPosition,
515-
required TextDirection textDirection,
516-
Set<Marker> markers = const <Marker>{},
517-
Set<Polygon> polygons = const <Polygon>{},
518-
Set<Polyline> polylines = const <Polyline>{},
519-
Set<Circle> circles = const <Circle>{},
520-
Set<TileOverlay> tileOverlays = const <TileOverlay>{},
521-
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
514+
required MapWidgetConfiguration widgetConfiguration,
515+
MapObjects mapObjects = const MapObjects(),
522516
Map<String, dynamic> mapOptions = const <String, dynamic>{},
523517
}) {
524518
if (defaultTargetPlatform == TargetPlatform.android &&
@@ -596,13 +590,14 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
596590
Map<String, dynamic> mapOptions = const <String, dynamic>{},
597591
}) {
598592
final Map<String, dynamic> creationParams = <String, dynamic>{
599-
'initialCameraPosition': initialCameraPosition.toMap(),
593+
'initialCameraPosition':
594+
widgetConfiguration.initialCameraPosition.toMap(),
600595
'options': mapOptions,
601-
'markersToAdd': serializeMarkerSet(markers),
602-
'polygonsToAdd': serializePolygonSet(polygons),
603-
'polylinesToAdd': serializePolylineSet(polylines),
604-
'circlesToAdd': serializeCircleSet(circles),
605-
'tileOverlaysToAdd': serializeTileOverlaySet(tileOverlays),
596+
'markersToAdd': serializeMarkerSet(mapObjects.markers),
597+
'polygonsToAdd': serializePolygonSet(mapObjects.polygons),
598+
'polylinesToAdd': serializePolylineSet(mapObjects.polylines),
599+
'circlesToAdd': serializeCircleSet(mapObjects.circles),
600+
'tileOverlaysToAdd': serializeTileOverlaySet(mapObjects.tileOverlays),
606601
};
607602

608603
if (defaultTargetPlatform == TargetPlatform.android) {
@@ -615,8 +610,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
615610
) {
616611
return AndroidViewSurface(
617612
controller: controller as AndroidViewController,
618-
gestureRecognizers: gestureRecognizers ??
619-
const <Factory<OneSequenceGestureRecognizer>>{},
613+
gestureRecognizers: widgetConfiguration.gestureRecognizers,
620614
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
621615
);
622616
},
@@ -625,7 +619,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
625619
PlatformViewsService.initSurfaceAndroidView(
626620
id: params.id,
627621
viewType: 'plugins.flutter.io/google_maps',
628-
layoutDirection: textDirection,
622+
layoutDirection: widgetConfiguration.textDirection,
629623
creationParams: creationParams,
630624
creationParamsCodec: const StandardMessageCodec(),
631625
onFocus: () => params.onFocusChanged(true),
@@ -645,7 +639,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
645639
return AndroidView(
646640
viewType: 'plugins.flutter.io/google_maps',
647641
onPlatformViewCreated: onPlatformViewCreated,
648-
gestureRecognizers: gestureRecognizers,
642+
gestureRecognizers: widgetConfiguration.gestureRecognizers,
649643
creationParams: creationParams,
650644
creationParamsCodec: const StandardMessageCodec(),
651645
);
@@ -654,7 +648,7 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
654648
return UiKitView(
655649
viewType: 'plugins.flutter.io/google_maps',
656650
onPlatformViewCreated: onPlatformViewCreated,
657-
gestureRecognizers: gestureRecognizers,
651+
gestureRecognizers: widgetConfiguration.gestureRecognizers,
658652
creationParams: creationParams,
659653
creationParamsCodec: const StandardMessageCodec(),
660654
);
@@ -664,6 +658,53 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
664658
'$defaultTargetPlatform is not yet supported by the maps plugin');
665659
}
666660

661+
@override
662+
Widget buildViewWithConfiguration(
663+
int creationId,
664+
PlatformViewCreatedCallback onPlatformViewCreated, {
665+
required MapWidgetConfiguration widgetConfiguration,
666+
MapConfiguration mapConfiguration = const MapConfiguration(),
667+
MapObjects mapObjects = const MapObjects(),
668+
}) {
669+
return _buildView(
670+
creationId,
671+
onPlatformViewCreated,
672+
widgetConfiguration: widgetConfiguration,
673+
mapObjects: mapObjects,
674+
mapOptions: jsonForMapConfiguration(mapConfiguration),
675+
);
676+
}
677+
678+
@override
679+
Widget buildViewWithTextDirection(
680+
int creationId,
681+
PlatformViewCreatedCallback onPlatformViewCreated, {
682+
required CameraPosition initialCameraPosition,
683+
required TextDirection textDirection,
684+
Set<Marker> markers = const <Marker>{},
685+
Set<Polygon> polygons = const <Polygon>{},
686+
Set<Polyline> polylines = const <Polyline>{},
687+
Set<Circle> circles = const <Circle>{},
688+
Set<TileOverlay> tileOverlays = const <TileOverlay>{},
689+
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
690+
Map<String, dynamic> mapOptions = const <String, dynamic>{},
691+
}) {
692+
return _buildView(
693+
creationId,
694+
onPlatformViewCreated,
695+
widgetConfiguration: MapWidgetConfiguration(
696+
initialCameraPosition: initialCameraPosition,
697+
textDirection: textDirection),
698+
mapObjects: MapObjects(
699+
markers: markers,
700+
polygons: polygons,
701+
polylines: polylines,
702+
circles: circles,
703+
tileOverlays: tileOverlays),
704+
mapOptions: mapOptions,
705+
);
706+
}
707+
667708
@override
668709
Widget buildView(
669710
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
@@ -367,7 +383,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
367383
throw UnimplementedError('dispose() has not been implemented.');
368384
}
369385

370-
/// Returns a widget displaying the map view.
386+
/// Returns a widget displaying the map view - deprecated, use
387+
/// [buildViewWithConfiguration] instead.
371388
Widget buildView(
372389
int creationId,
373390
PlatformViewCreatedCallback onPlatformViewCreated, {
@@ -387,7 +404,8 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
387404
throw UnimplementedError('buildView() has not been implemented.');
388405
}
389406

390-
/// Returns a widget displaying the map view.
407+
/// Returns a widget displaying the map view - deprecated, use
408+
/// [buildViewWithConfiguration] instead.
391409
///
392410
/// This method is similar to [buildView], but contains a parameter for
393411
/// platforms that require a text direction.
@@ -401,12 +419,12 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
401419
PlatformViewCreatedCallback onPlatformViewCreated, {
402420
required CameraPosition initialCameraPosition,
403421
required TextDirection textDirection,
422+
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
404423
Set<Marker> markers = const <Marker>{},
405424
Set<Polygon> polygons = const <Polygon>{},
406425
Set<Polyline> polylines = const <Polyline>{},
407426
Set<Circle> circles = const <Circle>{},
408427
Set<TileOverlay> tileOverlays = const <TileOverlay>{},
409-
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
410428
Map<String, dynamic> mapOptions = const <String, dynamic>{},
411429
}) {
412430
return buildView(
@@ -422,4 +440,27 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
422440
mapOptions: mapOptions,
423441
);
424442
}
443+
444+
/// Returns a widget displaying the map view.
445+
Widget buildViewWithConfiguration(
446+
int creationId,
447+
PlatformViewCreatedCallback onPlatformViewCreated, {
448+
required MapWidgetConfiguration widgetConfiguration,
449+
MapConfiguration mapConfiguration = const MapConfiguration(),
450+
MapObjects mapObjects = const MapObjects(),
451+
}) {
452+
return buildViewWithTextDirection(
453+
creationId,
454+
onPlatformViewCreated,
455+
initialCameraPosition: widgetConfiguration.initialCameraPosition,
456+
textDirection: widgetConfiguration.textDirection,
457+
markers: mapObjects.markers,
458+
polygons: mapObjects.polygons,
459+
polylines: mapObjects.polylines,
460+
circles: mapObjects.circles,
461+
tileOverlays: mapObjects.tileOverlays,
462+
gestureRecognizers: widgetConfiguration.gestureRecognizers,
463+
mapOptions: jsonForMapConfiguration(mapConfiguration),
464+
);
465+
}
425466
}

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)