diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md index 6fc61e8eefc..4802eb9d144 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.8.1 + +* Improves Objective-C type handling. + ## 2.8.0 * Adds compatibility with SDK version 9.x for apps targetting iOS 15+. diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/ios/RunnerTests/FLTGoogleMapJSONConversionsConversionTests.m b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/ios/RunnerTests/FLTGoogleMapJSONConversionsConversionTests.m index cc654606d8c..e75fc046912 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/ios/RunnerTests/FLTGoogleMapJSONConversionsConversionTests.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/ios/RunnerTests/FLTGoogleMapJSONConversionsConversionTests.m @@ -16,6 +16,28 @@ @interface FLTGoogleMapJSONConversionsTests : XCTestCase @implementation FLTGoogleMapJSONConversionsTests +- (void)testGetValueOrNilWithValue { + NSString *key = @"key"; + NSString *value = @"value"; + NSDictionary *dict = @{key : value}; + + XCTAssertEqual(FGMGetValueOrNilFromDict(dict, key), value); +} + +- (void)testGetValueOrNilWithNoEntry { + NSString *key = @"key"; + NSDictionary *dict = @{}; + + XCTAssertNil(FGMGetValueOrNilFromDict(dict, key)); +} + +- (void)testGetValueOrNilWithNSNull { + NSString *key = @"key"; + NSDictionary *dict = @{key : [NSNull null]}; + + XCTAssertNil(FGMGetValueOrNilFromDict(dict, key)); +} + - (void)testLocationFromLatLong { NSArray *latlong = @[ @1, @2 ]; CLLocationCoordinate2D location = [FLTGoogleMapJSONConversions locationFromLatLong:latlong]; diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapJSONConversions.h b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapJSONConversions.h index 1fc8d003d91..c6f9fc76eba 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapJSONConversions.h +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapJSONConversions.h @@ -7,6 +7,9 @@ NS_ASSUME_NONNULL_BEGIN +/// Returns dict[key], or nil if dict[key] is NSNull. +extern id _Nullable FGMGetValueOrNilFromDict(NSDictionary *dict, NSString *key); + @interface FLTGoogleMapJSONConversions : NSObject + (CLLocationCoordinate2D)locationFromLatLong:(NSArray *)latlong; diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapJSONConversions.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapJSONConversions.m index 28307182f2c..f6ea7690222 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapJSONConversions.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapJSONConversions.m @@ -4,6 +4,12 @@ #import "FLTGoogleMapJSONConversions.h" +/// Returns dict[key], or nil if dict[key] is NSNull. +id FGMGetValueOrNilFromDict(NSDictionary *dict, NSString *key) { + id value = dict[key]; + return value == [NSNull null] ? nil : value; +} + @implementation FLTGoogleMapJSONConversions + (CLLocationCoordinate2D)locationFromLatLong:(NSArray *)latlong { diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapTileOverlayController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapTileOverlayController.m index 73eab6c1ead..bc56671f5cd 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapTileOverlayController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapTileOverlayController.m @@ -70,28 +70,28 @@ - (void)interpretTileOverlayOptions:(NSDictionary *)data { if (!data) { return; } - NSNumber *visible = data[@"visible"]; - if (visible != nil && visible != (id)[NSNull null]) { + NSNumber *visible = FGMGetValueOrNilFromDict(data, @"visible"); + if (visible) { [self setVisible:visible.boolValue]; } - NSNumber *transparency = data[@"transparency"]; - if (transparency != nil && transparency != (id)[NSNull null]) { + NSNumber *transparency = FGMGetValueOrNilFromDict(data, @"transparency"); + if (transparency) { [self setTransparency:transparency.floatValue]; } - NSNumber *zIndex = data[@"zIndex"]; - if (zIndex != nil && zIndex != (id)[NSNull null]) { + NSNumber *zIndex = FGMGetValueOrNilFromDict(data, @"zIndex"); + if (zIndex) { [self setZIndex:zIndex.intValue]; } - NSNumber *fadeIn = data[@"fadeIn"]; - if (fadeIn != nil && fadeIn != (id)[NSNull null]) { + NSNumber *fadeIn = FGMGetValueOrNilFromDict(data, @"fadeIn"); + if (fadeIn) { [self setFadeIn:fadeIn.boolValue]; } - NSNumber *tileSize = data[@"tileSize"]; - if (tileSize != nil && tileSize != (id)[NSNull null]) { + NSNumber *tileSize = FGMGetValueOrNilFromDict(data, @"tileSize"); + if (tileSize) { [self setTileSize:tileSize.integerValue]; } } diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapCircleController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapCircleController.m index 53bf69075c9..1eb74a19559 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapCircleController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapCircleController.m @@ -60,43 +60,43 @@ - (void)setFillColor:(UIColor *)color { } - (void)interpretCircleOptions:(NSDictionary *)data { - NSNumber *consumeTapEvents = data[@"consumeTapEvents"]; - if (consumeTapEvents && consumeTapEvents != (id)[NSNull null]) { + NSNumber *consumeTapEvents = FGMGetValueOrNilFromDict(data, @"consumeTapEvents"); + if (consumeTapEvents) { [self setConsumeTapEvents:consumeTapEvents.boolValue]; } - NSNumber *visible = data[@"visible"]; - if (visible && visible != (id)[NSNull null]) { + NSNumber *visible = FGMGetValueOrNilFromDict(data, @"visible"); + if (visible) { [self setVisible:[visible boolValue]]; } - NSNumber *zIndex = data[@"zIndex"]; - if (zIndex && zIndex != (id)[NSNull null]) { + NSNumber *zIndex = FGMGetValueOrNilFromDict(data, @"zIndex"); + if (zIndex) { [self setZIndex:[zIndex intValue]]; } - NSArray *center = data[@"center"]; - if (center && center != (id)[NSNull null]) { + NSArray *center = FGMGetValueOrNilFromDict(data, @"center"); + if (center) { [self setCenter:[FLTGoogleMapJSONConversions locationFromLatLong:center]]; } - NSNumber *radius = data[@"radius"]; - if (radius && radius != (id)[NSNull null]) { + NSNumber *radius = FGMGetValueOrNilFromDict(data, @"radius"); + if (radius) { [self setRadius:[radius floatValue]]; } - NSNumber *strokeColor = data[@"strokeColor"]; - if (strokeColor && strokeColor != (id)[NSNull null]) { + NSNumber *strokeColor = FGMGetValueOrNilFromDict(data, @"strokeColor"); + if (strokeColor) { [self setStrokeColor:[FLTGoogleMapJSONConversions colorFromRGBA:strokeColor]]; } - NSNumber *strokeWidth = data[@"strokeWidth"]; - if (strokeWidth && strokeWidth != (id)[NSNull null]) { + NSNumber *strokeWidth = FGMGetValueOrNilFromDict(data, @"strokeWidth"); + if (strokeWidth) { [self setStrokeWidth:[strokeWidth intValue]]; } - NSNumber *fillColor = data[@"fillColor"]; - if (fillColor && fillColor != (id)[NSNull null]) { + NSNumber *fillColor = FGMGetValueOrNilFromDict(data, @"fillColor"); + if (fillColor) { [self setFillColor:[FLTGoogleMapJSONConversions colorFromRGBA:fillColor]]; } } diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m index 4c747f3eeba..08fdf8cc7f4 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapController.m @@ -581,41 +581,41 @@ - (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordi } - (void)interpretMapOptions:(NSDictionary *)data { - NSArray *cameraTargetBounds = data[@"cameraTargetBounds"]; - if (cameraTargetBounds && cameraTargetBounds != (id)[NSNull null]) { + NSArray *cameraTargetBounds = FGMGetValueOrNilFromDict(data, @"cameraTargetBounds"); + if (cameraTargetBounds) { [self setCameraTargetBounds:cameraTargetBounds.count > 0 && cameraTargetBounds[0] != [NSNull null] ? [FLTGoogleMapJSONConversions coordinateBoundsFromLatLongs:cameraTargetBounds.firstObject] : nil]; } - NSNumber *compassEnabled = data[@"compassEnabled"]; - if (compassEnabled && compassEnabled != (id)[NSNull null]) { + NSNumber *compassEnabled = FGMGetValueOrNilFromDict(data, @"compassEnabled"); + if (compassEnabled) { [self setCompassEnabled:[compassEnabled boolValue]]; } - id indoorEnabled = data[@"indoorEnabled"]; - if (indoorEnabled && indoorEnabled != [NSNull null]) { + id indoorEnabled = FGMGetValueOrNilFromDict(data, @"indoorEnabled"); + if (indoorEnabled) { [self setIndoorEnabled:[indoorEnabled boolValue]]; } - id trafficEnabled = data[@"trafficEnabled"]; - if (trafficEnabled && trafficEnabled != [NSNull null]) { + id trafficEnabled = FGMGetValueOrNilFromDict(data, @"trafficEnabled"); + if (trafficEnabled) { [self setTrafficEnabled:[trafficEnabled boolValue]]; } - id buildingsEnabled = data[@"buildingsEnabled"]; - if (buildingsEnabled && buildingsEnabled != [NSNull null]) { + id buildingsEnabled = FGMGetValueOrNilFromDict(data, @"buildingsEnabled"); + if (buildingsEnabled) { [self setBuildingsEnabled:[buildingsEnabled boolValue]]; } - id mapType = data[@"mapType"]; - if (mapType && mapType != [NSNull null]) { + id mapType = FGMGetValueOrNilFromDict(data, @"mapType"); + if (mapType) { [self setMapType:[FLTGoogleMapJSONConversions mapViewTypeFromTypeValue:mapType]]; } - NSArray *zoomData = data[@"minMaxZoomPreference"]; - if (zoomData && zoomData != (id)[NSNull null]) { + NSArray *zoomData = FGMGetValueOrNilFromDict(data, @"minMaxZoomPreference"); + if (zoomData) { float minZoom = (zoomData[0] == [NSNull null]) ? kGMSMinZoomLevel : [zoomData[0] floatValue]; float maxZoom = (zoomData[1] == [NSNull null]) ? kGMSMaxZoomLevel : [zoomData[1] floatValue]; [self setMinZoom:minZoom maxZoom:maxZoom]; } - NSArray *paddingData = data[@"padding"]; + NSArray *paddingData = FGMGetValueOrNilFromDict(data, @"padding"); if (paddingData) { float top = (paddingData[0] == [NSNull null]) ? 0 : [paddingData[0] floatValue]; float left = (paddingData[1] == [NSNull null]) ? 0 : [paddingData[1] floatValue]; @@ -624,35 +624,35 @@ - (void)interpretMapOptions:(NSDictionary *)data { [self setPaddingTop:top left:left bottom:bottom right:right]; } - NSNumber *rotateGesturesEnabled = data[@"rotateGesturesEnabled"]; - if (rotateGesturesEnabled && rotateGesturesEnabled != (id)[NSNull null]) { + NSNumber *rotateGesturesEnabled = FGMGetValueOrNilFromDict(data, @"rotateGesturesEnabled"); + if (rotateGesturesEnabled) { [self setRotateGesturesEnabled:[rotateGesturesEnabled boolValue]]; } - NSNumber *scrollGesturesEnabled = data[@"scrollGesturesEnabled"]; - if (scrollGesturesEnabled && scrollGesturesEnabled != (id)[NSNull null]) { + NSNumber *scrollGesturesEnabled = FGMGetValueOrNilFromDict(data, @"scrollGesturesEnabled"); + if (scrollGesturesEnabled) { [self setScrollGesturesEnabled:[scrollGesturesEnabled boolValue]]; } - NSNumber *tiltGesturesEnabled = data[@"tiltGesturesEnabled"]; - if (tiltGesturesEnabled && tiltGesturesEnabled != (id)[NSNull null]) { + NSNumber *tiltGesturesEnabled = FGMGetValueOrNilFromDict(data, @"tiltGesturesEnabled"); + if (tiltGesturesEnabled) { [self setTiltGesturesEnabled:[tiltGesturesEnabled boolValue]]; } - NSNumber *trackCameraPosition = data[@"trackCameraPosition"]; - if (trackCameraPosition && trackCameraPosition != (id)[NSNull null]) { + NSNumber *trackCameraPosition = FGMGetValueOrNilFromDict(data, @"trackCameraPosition"); + if (trackCameraPosition) { [self setTrackCameraPosition:[trackCameraPosition boolValue]]; } - NSNumber *zoomGesturesEnabled = data[@"zoomGesturesEnabled"]; - if (zoomGesturesEnabled && zoomGesturesEnabled != (id)[NSNull null]) { + NSNumber *zoomGesturesEnabled = FGMGetValueOrNilFromDict(data, @"zoomGesturesEnabled"); + if (zoomGesturesEnabled) { [self setZoomGesturesEnabled:[zoomGesturesEnabled boolValue]]; } - NSNumber *myLocationEnabled = data[@"myLocationEnabled"]; - if (myLocationEnabled && myLocationEnabled != (id)[NSNull null]) { + NSNumber *myLocationEnabled = FGMGetValueOrNilFromDict(data, @"myLocationEnabled"); + if (myLocationEnabled) { [self setMyLocationEnabled:[myLocationEnabled boolValue]]; } - NSNumber *myLocationButtonEnabled = data[@"myLocationButtonEnabled"]; - if (myLocationButtonEnabled && myLocationButtonEnabled != (id)[NSNull null]) { + NSNumber *myLocationButtonEnabled = FGMGetValueOrNilFromDict(data, @"myLocationButtonEnabled"); + if (myLocationButtonEnabled) { [self setMyLocationButtonEnabled:[myLocationButtonEnabled boolValue]]; } - NSString *style = data[@"style"]; + NSString *style = FGMGetValueOrNilFromDict(data, @"style"); if (style) { self.styleError = [self setMapStyle:style]; } diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m index b816e7ee914..1bc7d2a8db8 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapMarkerController.m @@ -93,60 +93,60 @@ - (void)setZIndex:(int)zIndex { - (void)interpretMarkerOptions:(NSDictionary *)data registrar:(NSObject *)registrar screenScale:(CGFloat)screenScale { - NSNumber *alpha = data[@"alpha"]; - if (alpha && alpha != (id)[NSNull null]) { + NSNumber *alpha = FGMGetValueOrNilFromDict(data, @"alpha"); + if (alpha) { [self setAlpha:[alpha floatValue]]; } - NSArray *anchor = data[@"anchor"]; - if (anchor && anchor != (id)[NSNull null]) { + NSArray *anchor = FGMGetValueOrNilFromDict(data, @"anchor"); + if (anchor) { [self setAnchor:[FLTGoogleMapJSONConversions pointFromArray:anchor]]; } - NSNumber *draggable = data[@"draggable"]; - if (draggable && draggable != (id)[NSNull null]) { + NSNumber *draggable = FGMGetValueOrNilFromDict(data, @"draggable"); + if (draggable) { [self setDraggable:[draggable boolValue]]; } - NSArray *icon = data[@"icon"]; - if (icon && icon != (id)[NSNull null]) { + NSArray *icon = FGMGetValueOrNilFromDict(data, @"icon"); + if (icon) { UIImage *image = [self extractIconFromData:icon registrar:registrar screenScale:screenScale]; [self setIcon:image]; } - NSNumber *flat = data[@"flat"]; - if (flat && flat != (id)[NSNull null]) { + NSNumber *flat = FGMGetValueOrNilFromDict(data, @"flat"); + if (flat) { [self setFlat:[flat boolValue]]; } - NSNumber *consumeTapEvents = data[@"consumeTapEvents"]; - if (consumeTapEvents && consumeTapEvents != (id)[NSNull null]) { + NSNumber *consumeTapEvents = FGMGetValueOrNilFromDict(data, @"consumeTapEvents"); + if (consumeTapEvents) { [self setConsumeTapEvents:[consumeTapEvents boolValue]]; } [self interpretInfoWindow:data]; - NSArray *position = data[@"position"]; - if (position && position != (id)[NSNull null]) { + NSArray *position = FGMGetValueOrNilFromDict(data, @"position"); + if (position) { [self setPosition:[FLTGoogleMapJSONConversions locationFromLatLong:position]]; } - NSNumber *rotation = data[@"rotation"]; - if (rotation && rotation != (id)[NSNull null]) { + NSNumber *rotation = FGMGetValueOrNilFromDict(data, @"rotation"); + if (rotation) { [self setRotation:[rotation doubleValue]]; } - NSNumber *visible = data[@"visible"]; - if (visible && visible != (id)[NSNull null]) { + NSNumber *visible = FGMGetValueOrNilFromDict(data, @"visible"); + if (visible) { [self setVisible:[visible boolValue]]; } - NSNumber *zIndex = data[@"zIndex"]; - if (zIndex && zIndex != (id)[NSNull null]) { + NSNumber *zIndex = FGMGetValueOrNilFromDict(data, @"zIndex"); + if (zIndex) { [self setZIndex:[zIndex intValue]]; } } - (void)interpretInfoWindow:(NSDictionary *)data { - NSDictionary *infoWindow = data[@"infoWindow"]; - if (infoWindow && infoWindow != (id)[NSNull null]) { - NSString *title = infoWindow[@"title"]; - NSString *snippet = infoWindow[@"snippet"]; - if (title && title != (id)[NSNull null]) { + NSDictionary *infoWindow = FGMGetValueOrNilFromDict(data, @"infoWindow"); + if (infoWindow) { + NSString *title = FGMGetValueOrNilFromDict(infoWindow, @"title"); + NSString *snippet = FGMGetValueOrNilFromDict(infoWindow, @"snippet"); + if (title) { [self setInfoWindowTitle:title snippet:snippet]; } NSArray *infoWindowAnchor = infoWindow[@"infoWindowAnchor"]; - if (infoWindowAnchor && infoWindowAnchor != (id)[NSNull null]) { + if (infoWindowAnchor) { [self setInfoWindowAnchor:[FLTGoogleMapJSONConversions pointFromArray:infoWindowAnchor]]; } } @@ -221,15 +221,16 @@ - (UIImage *)extractIconFromData:(NSArray *)iconData @throw exception; } - NSString *assetName = assetData[@"assetName"]; - NSString *scalingMode = assetData[@"bitmapScaling"]; + NSString *assetName = FGMGetValueOrNilFromDict(assetData, @"assetName"); + NSString *scalingMode = FGMGetValueOrNilFromDict(assetData, @"bitmapScaling"); image = [UIImage imageNamed:[registrar lookupKeyForAsset:assetName]]; if ([scalingMode isEqualToString:@"auto"]) { - NSNumber *width = assetData[@"width"]; - NSNumber *height = assetData[@"height"]; - CGFloat imagePixelRatio = [assetData[@"imagePixelRatio"] doubleValue]; + NSNumber *width = FGMGetValueOrNilFromDict(assetData, @"width"); + NSNumber *height = FGMGetValueOrNilFromDict(assetData, @"height"); + CGFloat imagePixelRatio = + [FGMGetValueOrNilFromDict(assetData, @"imagePixelRatio") doubleValue]; if (width || height) { image = [FLTGoogleMapMarkerController scaledImage:image withScale:screenScale]; @@ -252,15 +253,16 @@ - (UIImage *)extractIconFromData:(NSArray *)iconData @throw exception; } - FlutterStandardTypedData *bytes = byteData[@"byteData"]; - NSString *scalingMode = byteData[@"bitmapScaling"]; + FlutterStandardTypedData *bytes = FGMGetValueOrNilFromDict(byteData, @"byteData"); + NSString *scalingMode = FGMGetValueOrNilFromDict(byteData, @"bitmapScaling"); @try { image = [UIImage imageWithData:[bytes data] scale:screenScale]; if ([scalingMode isEqualToString:@"auto"]) { - NSNumber *width = byteData[@"width"]; - NSNumber *height = byteData[@"height"]; - CGFloat imagePixelRatio = [byteData[@"imagePixelRatio"] doubleValue]; + NSNumber *width = FGMGetValueOrNilFromDict(byteData, @"width"); + NSNumber *height = FGMGetValueOrNilFromDict(byteData, @"height"); + CGFloat imagePixelRatio = + [FGMGetValueOrNilFromDict(byteData, @"imagePixelRatio") doubleValue]; if (width || height) { // Before scaling the image, image must be in screenScale diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapPolygonController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapPolygonController.m index 398adfcacec..d8dc47def60 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapPolygonController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapPolygonController.m @@ -73,43 +73,43 @@ - (void)setStrokeWidth:(CGFloat)width { - (void)interpretPolygonOptions:(NSDictionary *)data registrar:(NSObject *)registrar { - NSNumber *consumeTapEvents = data[@"consumeTapEvents"]; - if (consumeTapEvents && consumeTapEvents != (id)[NSNull null]) { + NSNumber *consumeTapEvents = FGMGetValueOrNilFromDict(data, @"consumeTapEvents"); + if (consumeTapEvents) { [self setConsumeTapEvents:[consumeTapEvents boolValue]]; } - NSNumber *visible = data[@"visible"]; - if (visible && visible != (id)[NSNull null]) { + NSNumber *visible = FGMGetValueOrNilFromDict(data, @"visible"); + if (visible) { [self setVisible:[visible boolValue]]; } - NSNumber *zIndex = data[@"zIndex"]; - if (zIndex && zIndex != (id)[NSNull null]) { + NSNumber *zIndex = FGMGetValueOrNilFromDict(data, @"zIndex"); + if (zIndex) { [self setZIndex:[zIndex intValue]]; } - NSArray *points = data[@"points"]; - if (points && points != (id)[NSNull null]) { + NSArray *points = FGMGetValueOrNilFromDict(data, @"points"); + if (points) { [self setPoints:[FLTGoogleMapJSONConversions pointsFromLatLongs:points]]; } - NSArray *holes = data[@"holes"]; - if (holes && holes != (id)[NSNull null]) { + NSArray *holes = FGMGetValueOrNilFromDict(data, @"holes"); + if (holes) { [self setHoles:[FLTGoogleMapJSONConversions holesFromPointsArray:holes]]; } - NSNumber *fillColor = data[@"fillColor"]; - if (fillColor && fillColor != (id)[NSNull null]) { + NSNumber *fillColor = FGMGetValueOrNilFromDict(data, @"fillColor"); + if (fillColor) { [self setFillColor:[FLTGoogleMapJSONConversions colorFromRGBA:fillColor]]; } - NSNumber *strokeColor = data[@"strokeColor"]; - if (strokeColor && strokeColor != (id)[NSNull null]) { + NSNumber *strokeColor = FGMGetValueOrNilFromDict(data, @"strokeColor"); + if (strokeColor) { [self setStrokeColor:[FLTGoogleMapJSONConversions colorFromRGBA:strokeColor]]; } - NSNumber *strokeWidth = data[@"strokeWidth"]; - if (strokeWidth && strokeWidth != (id)[NSNull null]) { + NSNumber *strokeWidth = FGMGetValueOrNilFromDict(data, @"strokeWidth"); + if (strokeWidth) { [self setStrokeWidth:[strokeWidth intValue]]; } } diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapPolylineController.m b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapPolylineController.m index 47334576b1c..a97f372d6fd 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapPolylineController.m +++ b/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapPolylineController.m @@ -12,12 +12,6 @@ @interface FLTGoogleMapPolylineController () @end -/// Returns dict[key], or nil if dict[key] is NSNull. -static id GetValueOrNilFromDict(NSDictionary *dict, NSString *key) { - id value = dict[key]; - return value == [NSNull null] ? nil : value; -} - @implementation FLTGoogleMapPolylineController - (instancetype)initPolylineWithPath:(GMSMutablePath *)path @@ -71,42 +65,42 @@ - (void)setPattern:(NSArray *)styles lengths:(NSArray *)registrar { - NSNumber *consumeTapEvents = GetValueOrNilFromDict(data, @"consumeTapEvents"); + NSNumber *consumeTapEvents = FGMGetValueOrNilFromDict(data, @"consumeTapEvents"); if (consumeTapEvents) { [self setConsumeTapEvents:[consumeTapEvents boolValue]]; } - NSNumber *visible = GetValueOrNilFromDict(data, @"visible"); + NSNumber *visible = FGMGetValueOrNilFromDict(data, @"visible"); if (visible) { [self setVisible:[visible boolValue]]; } - NSNumber *zIndex = GetValueOrNilFromDict(data, @"zIndex"); + NSNumber *zIndex = FGMGetValueOrNilFromDict(data, @"zIndex"); if (zIndex) { [self setZIndex:[zIndex intValue]]; } - NSArray *points = GetValueOrNilFromDict(data, @"points"); + NSArray *points = FGMGetValueOrNilFromDict(data, @"points"); if (points) { [self setPoints:[FLTGoogleMapJSONConversions pointsFromLatLongs:points]]; } - NSNumber *strokeColor = GetValueOrNilFromDict(data, @"color"); + NSNumber *strokeColor = FGMGetValueOrNilFromDict(data, @"color"); if (strokeColor) { [self setColor:[FLTGoogleMapJSONConversions colorFromRGBA:strokeColor]]; } - NSNumber *strokeWidth = GetValueOrNilFromDict(data, @"width"); + NSNumber *strokeWidth = FGMGetValueOrNilFromDict(data, @"width"); if (strokeWidth) { [self setStrokeWidth:[strokeWidth intValue]]; } - NSNumber *geodesic = GetValueOrNilFromDict(data, @"geodesic"); + NSNumber *geodesic = FGMGetValueOrNilFromDict(data, @"geodesic"); if (geodesic) { [self setGeodesic:geodesic.boolValue]; } - NSArray *patterns = GetValueOrNilFromDict(data, @"pattern"); + NSArray *patterns = FGMGetValueOrNilFromDict(data, @"pattern"); if (patterns) { [self setPattern:[FLTGoogleMapJSONConversions strokeStylesFromPatterns:patterns diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml index e2dc69dd1bb..0314d44e46f 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_ios description: iOS implementation of the google_maps_flutter plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 2.8.0 +version: 2.8.1 environment: sdk: ^3.2.3