Skip to content

Commit fe2475f

Browse files
committed
Move MarkerType to MapConfiguration
1 parent a9261a3 commit fe2475f

File tree

26 files changed

+87
-76
lines changed

26 files changed

+87
-76
lines changed

packages/google_maps_flutter/google_maps_flutter/example/lib/clustering.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:math';
66

77
import 'package:flutter/material.dart';
88
import 'package:google_maps_flutter/google_maps_flutter.dart';
9-
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
109

1110
import 'page.dart';
1211

packages/google_maps_flutter/google_maps_flutter/example/lib/marker_icons.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'dart:async';
1010
import 'package:flutter/foundation.dart';
1111
import 'package:flutter/material.dart';
1212
import 'package:google_maps_flutter/google_maps_flutter.dart';
13-
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
1413

1514
import 'custom_marker_icon.dart';
1615
import 'page.dart';

packages/google_maps_flutter/google_maps_flutter/example/lib/place_marker.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'dart:typed_data';
1010

1111
import 'package:flutter/material.dart';
1212
import 'package:google_maps_flutter/google_maps_flutter.dart';
13-
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
1413

1514
import 'custom_marker_icon.dart';
1615
import 'page.dart';

packages/google_maps_flutter/google_maps_flutter/example/lib/readme_sample_advanced_markers.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import 'package:flutter/material.dart';
88
import 'package:google_maps_flutter/google_maps_flutter.dart';
9-
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
109

1110
void main() => runApp(const MyApp());
1211

packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'dart:async';
99
import 'package:flutter/foundation.dart';
1010
import 'package:flutter/gestures.dart';
1111
import 'package:flutter/material.dart';
12+
import 'package:flutter/services.dart';
1213
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
1314
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
1415

@@ -45,6 +46,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
4546
MapType,
4647
Marker,
4748
MarkerId,
49+
MarkerType,
4850
MinMaxZoomPreference,
4951
PatternItem,
5052
Polygon,

packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,18 @@ class GoogleMap extends StatefulWidget {
358358
/// for more details.
359359
final String? mapId;
360360

361-
/// Indicates whether map should use [AdvancedMarker]s or [Marker]s.
361+
/// Indicates whether map uses [AdvancedMarker]s or [Marker]s.
362+
///
363+
/// [AdvancedMarker] and [Marker]s classes might not be related to each other
364+
/// in the platform implementation. It's important to set the correct
365+
/// [MarkerType] so that the platform implementation can handle the markers:
366+
/// * If [MarkerType.advancedMarker] is used, all markers must be of type
367+
/// [AdvancedMarker].
368+
/// * If [MarkerType.marker] is used, markers cannot be of type
369+
/// [AdvancedMarker].
370+
///
371+
/// While some features work with either type, using the incorrect type
372+
/// may result in unexpected behavior.
362373
final MarkerType markerType;
363374

364375
/// Creates a [State] for this [GoogleMap].
@@ -394,7 +405,6 @@ class _GoogleMapState extends State<GoogleMap> {
394405
TextDirection.ltr,
395406
initialCameraPosition: widget.initialCameraPosition,
396407
gestureRecognizers: widget.gestureRecognizers,
397-
markerType: widget.markerType,
398408
),
399409
mapObjects: MapObjects(
400410
markers: widget.markers,

packages/google_maps_flutter/google_maps_flutter_android/example/lib/example_google_map.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ class _ExampleGoogleMapState extends State<ExampleGoogleMap> {
421421
TextDirection.ltr,
422422
initialCameraPosition: widget.initialCameraPosition,
423423
gestureRecognizers: widget.gestureRecognizers,
424-
markerType: widget.markerType,
425424
),
426425
mapObjects: MapObjects(
427426
markers: widget.markers,

packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
550550
PlatformViewCreatedCallback onPlatformViewCreated, {
551551
required PlatformMapConfiguration mapConfiguration,
552552
required MapWidgetConfiguration widgetConfiguration,
553-
required MarkerType markerType,
554553
MapObjects mapObjects = const MapObjects(),
555554
}) {
556555
assert(
@@ -647,7 +646,6 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
647646
mapObjects: mapObjects,
648647
mapConfiguration:
649648
_platformMapConfigurationFromMapConfiguration(mapConfiguration),
650-
markerType: widgetConfiguration.markerType,
651649
);
652650
}
653651

@@ -673,7 +671,6 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
673671
widgetConfiguration: MapWidgetConfiguration(
674672
initialCameraPosition: initialCameraPosition,
675673
textDirection: textDirection,
676-
markerType: markerType,
677674
),
678675
mapObjects: MapObjects(
679676
markers: markers,
@@ -683,7 +680,6 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
683680
clusterManagers: clusterManagers,
684681
tileOverlays: tileOverlays),
685682
mapConfiguration: _platformMapConfigurationFromOptionsJson(mapOptions),
686-
markerType: markerType,
687683
);
688684
}
689685

@@ -947,13 +943,6 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
947943
}
948944
}
949945

950-
PlatformMarkerType _platformMarkerTypeFromMarkerType(MarkerType markerType) {
951-
return switch (markerType) {
952-
MarkerType.marker => PlatformMarkerType.marker,
953-
MarkerType.advancedMarker => PlatformMarkerType.advancedMarker,
954-
};
955-
}
956-
957946
/// Convert [MapBitmapScaling] from platform interface to [PlatformMapBitmapScaling] Pigeon.
958947
@visibleForTesting
959948
static PlatformMapBitmapScaling platformMapBitmapScalingFromScaling(
@@ -1299,6 +1288,14 @@ PlatformEdgeInsets? _platformEdgeInsetsFromEdgeInsets(EdgeInsets? insets) {
12991288
right: insets.right);
13001289
}
13011290

1291+
PlatformMarkerType? _platformMarkerTypeFromMarkerType(MarkerType? markerType) {
1292+
return switch (markerType) {
1293+
null => null,
1294+
MarkerType.marker => PlatformMarkerType.marker,
1295+
MarkerType.advancedMarker => PlatformMarkerType.advancedMarker,
1296+
};
1297+
}
1298+
13021299
PlatformMapConfiguration _platformMapConfigurationFromMapConfiguration(
13031300
MapConfiguration config) {
13041301
return PlatformMapConfiguration(
@@ -1322,6 +1319,7 @@ PlatformMapConfiguration _platformMapConfigurationFromMapConfiguration(
13221319
trafficEnabled: config.trafficEnabled,
13231320
buildingsEnabled: config.buildingsEnabled,
13241321
liteModeEnabled: config.liteModeEnabled,
1322+
markerType: _platformMarkerTypeFromMarkerType(config.markerType),
13251323
mapId: config.mapId,
13261324
style: config.style,
13271325
);
@@ -1363,6 +1361,7 @@ PlatformMapConfiguration _platformMapConfigurationFromOptionsJson(
13631361
trafficEnabled: options['trafficEnabled'] as bool?,
13641362
buildingsEnabled: options['buildingsEnabled'] as bool?,
13651363
liteModeEnabled: options['liteModeEnabled'] as bool?,
1364+
markerType: _platformMarkerTypeFromIndex(options['markerType'] as int?),
13661365
mapId: options['mapId'] as String?,
13671366
style: options['style'] as String?,
13681367
);
@@ -1430,6 +1429,14 @@ PlatformZoomRange? _platformZoomRangeFromMinMaxZoomPreferenceJson(
14301429
return PlatformZoomRange(min: minMaxZoom[0], max: minMaxZoom[1]);
14311430
}
14321431

1432+
PlatformMarkerType _platformMarkerTypeFromIndex(int? index) {
1433+
return switch (index) {
1434+
0 => PlatformMarkerType.marker,
1435+
1 => PlatformMarkerType.advancedMarker,
1436+
_ => PlatformMarkerType.marker,
1437+
};
1438+
}
1439+
14331440
/// Converts platform interface's JointType to Pigeon's PlatformJointType.
14341441
@visibleForTesting
14351442
PlatformJointType platformJointTypeFromJointType(JointType jointType) {

packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ class PlatformMapConfiguration {
490490
required this.trafficEnabled,
491491
required this.buildingsEnabled,
492492
required this.liteModeEnabled,
493+
required this.markerType,
493494
required this.mapId,
494495
required this.style,
495496
});
@@ -512,6 +513,7 @@ class PlatformMapConfiguration {
512513
final bool? trafficEnabled;
513514
final bool? buildingsEnabled;
514515
final bool? liteModeEnabled;
516+
final PlatformMarkerType? markerType;
515517
final String? mapId;
516518
final String? style;
517519
}

packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@ void main() {
10831083
widgetConfiguration: const MapWidgetConfiguration(
10841084
initialCameraPosition: CameraPosition(target: LatLng(0, 0), zoom: 1),
10851085
textDirection: TextDirection.ltr,
1086-
markerType: MarkerType.marker,
10871086
),
10881087
);
10891088

@@ -1327,7 +1326,6 @@ void main() {
13271326
widgetConfiguration: const MapWidgetConfiguration(
13281327
initialCameraPosition: CameraPosition(target: LatLng(0, 0), zoom: 1),
13291328
textDirection: TextDirection.ltr,
1330-
markerType: MarkerType.marker,
13311329
));
13321330

13331331
expect(widget, isA<PlatformViewLink>());
@@ -1342,7 +1340,6 @@ void main() {
13421340
widgetConfiguration: const MapWidgetConfiguration(
13431341
initialCameraPosition: CameraPosition(target: LatLng(0, 0), zoom: 1),
13441342
textDirection: TextDirection.ltr,
1345-
markerType: MarkerType.marker,
13461343
),
13471344
);
13481345

@@ -1384,7 +1381,6 @@ void main() {
13841381
widgetConfiguration: const MapWidgetConfiguration(
13851382
initialCameraPosition: CameraPosition(target: LatLng(0, 0), zoom: 1),
13861383
textDirection: TextDirection.ltr,
1387-
markerType: MarkerType.marker,
13881384
),
13891385
// Here deprecated cloudMapId is used to test that creation params have
13901386
// the correct mapId.
@@ -1432,7 +1428,6 @@ void main() {
14321428
widgetConfiguration: const MapWidgetConfiguration(
14331429
initialCameraPosition: CameraPosition(target: LatLng(0, 0), zoom: 1),
14341430
textDirection: TextDirection.ltr,
1435-
markerType: MarkerType.marker,
14361431
),
14371432
mapConfiguration: const MapConfiguration(mapId: mapId)));
14381433

@@ -1453,15 +1448,16 @@ void main() {
14531448
widgetConfiguration: const MapWidgetConfiguration(
14541449
initialCameraPosition: CameraPosition(target: LatLng(0, 0), zoom: 1),
14551450
textDirection: TextDirection.ltr,
1456-
markerType: MarkerType.advancedMarker,
14571451
),
14581452
);
14591453

14601454
expect(widget, isA<AndroidView>());
14611455
final dynamic creationParams = (widget as AndroidView).creationParams;
14621456
expect(creationParams, isA<PlatformMapViewCreationParams>());
14631457
expect(
1464-
(creationParams as PlatformMapViewCreationParams).markerType,
1458+
(creationParams as PlatformMapViewCreationParams)
1459+
.mapConfiguration
1460+
.markerType,
14651461
PlatformMarkerType.advancedMarker,
14661462
);
14671463

@@ -1471,13 +1467,13 @@ void main() {
14711467
widgetConfiguration: const MapWidgetConfiguration(
14721468
initialCameraPosition: CameraPosition(target: LatLng(0, 0), zoom: 1),
14731469
textDirection: TextDirection.ltr,
1474-
markerType: MarkerType.marker,
14751470
),
14761471
);
14771472
expect(widget2, isA<AndroidView>());
14781473
expect(
14791474
((widget2 as AndroidView).creationParams
14801475
as PlatformMapViewCreationParams)
1476+
.mapConfiguration
14811477
.markerType,
14821478
PlatformMarkerType.marker,
14831479
);

0 commit comments

Comments
 (0)