From 6dc8d4a2a851197a455f2b9ab56e9740b9297cde Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Thu, 30 Nov 2023 10:12:27 -0800 Subject: [PATCH] Null check for adId argument. (#967) * Added null validation to the create method in GoogleMobileAdsViewFactory.java * Remove deprecated uses of describeEnum * Removed old dependency --- .../googlemobileads/GoogleMobileAdsViewFactory.java | 3 +++ .../google_mobile_ads/lib/src/ad_containers.dart | 2 +- .../lib/src/ad_instance_manager.dart | 12 +++++------- packages/google_mobile_ads/pubspec.yaml | 3 +-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsViewFactory.java b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsViewFactory.java index ed14a3e7d..43d6437fb 100644 --- a/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsViewFactory.java +++ b/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsViewFactory.java @@ -56,6 +56,9 @@ public GoogleMobileAdsViewFactory(@NonNull AdInstanceManager manager) { @Override public PlatformView create(Context context, int viewId, Object args) { + if (args == null) { + return getErrorView(context, 0); + } final Integer adId = (Integer) args; FlutterAd ad = manager.adForId(adId); if (ad == null || ad.getPlatformView() == null) { diff --git a/packages/google_mobile_ads/lib/src/ad_containers.dart b/packages/google_mobile_ads/lib/src/ad_containers.dart index c49bbbfbc..273248562 100644 --- a/packages/google_mobile_ads/lib/src/ad_containers.dart +++ b/packages/google_mobile_ads/lib/src/ad_containers.dart @@ -418,7 +418,7 @@ class AdSize { final num? height = await instanceManager.channel.invokeMethod( 'AdSize#getAnchoredAdaptiveBannerAdSize', { - 'orientation': describeEnum(orientation), + 'orientation': orientation.name, 'width': width, }, ); diff --git a/packages/google_mobile_ads/lib/src/ad_instance_manager.dart b/packages/google_mobile_ads/lib/src/ad_instance_manager.dart index f89040c94..d6d994b56 100644 --- a/packages/google_mobile_ads/lib/src/ad_instance_manager.dart +++ b/packages/google_mobile_ads/lib/src/ad_instance_manager.dart @@ -923,7 +923,7 @@ class AdMessageCodec extends StandardMessageCodec { writeValue(buffer, value.message); } else if (value is AdapterInitializationState) { buffer.putUint8(_valueInitializationState); - writeValue(buffer, describeEnum(value)); + writeValue(buffer, value.name); } else if (value is AdapterStatus) { buffer.putUint8(_valueAdapterStatus); writeValue(buffer, value.state); @@ -1015,8 +1015,7 @@ class AdMessageCodec extends StandardMessageCodec { Orientation? orientation; if (orientationStr != null) { orientation = Orientation.values.firstWhere( - (Orientation orientation) => - describeEnum(orientation) == orientationStr, + (Orientation orientation) => orientation.name == orientationStr, ); } return AnchoredAdaptiveBannerAdSize( @@ -1029,8 +1028,7 @@ class AdMessageCodec extends StandardMessageCodec { readValueOfType(buffer.getUint8(), buffer); return SmartBannerAdSize( Orientation.values.firstWhere( - (Orientation orientation) => - describeEnum(orientation) == orientationStr, + (Orientation orientation) => orientation.name == orientationStr, ), ); case _valueAdSize: @@ -1256,14 +1254,14 @@ class AdMessageCodec extends StandardMessageCodec { buffer.putUint8(_valueAnchoredAdaptiveBannerAdSize); var orientationValue; if (value.orientation != null) { - orientationValue = describeEnum(value.orientation as Orientation); + orientationValue = (value.orientation as Orientation).name; } writeValue(buffer, orientationValue); writeValue(buffer, value.width); } else if (value is SmartBannerAdSize) { buffer.putUint8(_valueSmartBannerAdSize); if (defaultTargetPlatform == TargetPlatform.iOS) { - writeValue(buffer, describeEnum(value.orientation)); + writeValue(buffer, value.orientation.name); } } else if (value is FluidAdSize) { buffer.putUint8(_valueFluidAdSize); diff --git a/packages/google_mobile_ads/pubspec.yaml b/packages/google_mobile_ads/pubspec.yaml index 45fb9adbd..b29345d03 100644 --- a/packages/google_mobile_ads/pubspec.yaml +++ b/packages/google_mobile_ads/pubspec.yaml @@ -44,10 +44,9 @@ dev_dependencies: build_runner: ^2.1.10 flutter_test: sdk: flutter - flutter_plugin_tools: ^0.8.5 webview_flutter_platform_interface: ^2.1.0 environment: - sdk: ">=2.14.0 <3.0.0" + sdk: ">=2.15.0 <4.0.0" flutter: ">=3.7.0"