Skip to content

Commit

Permalink
Null check for adId argument. (#967)
Browse files Browse the repository at this point in the history
* Added null validation to the create method in GoogleMobileAdsViewFactory.java
* Remove deprecated uses of describeEnum
* Removed old dependency
  • Loading branch information
LTPhantom authored Nov 30, 2023
1 parent 56ed176 commit 6dc8d4a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/google_mobile_ads/lib/src/ad_containers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class AdSize {
final num? height = await instanceManager.channel.invokeMethod<num?>(
'AdSize#getAnchoredAdaptiveBannerAdSize',
<String, Object?>{
'orientation': describeEnum(orientation),
'orientation': orientation.name,
'width': width,
},
);
Expand Down
12 changes: 5 additions & 7 deletions packages/google_mobile_ads/lib/src/ad_instance_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions packages/google_mobile_ads/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 6dc8d4a

Please sign in to comment.