diff --git a/packages/firebase_admob/CHANGELOG.md b/packages/firebase_admob/CHANGELOG.md index 5a8dc9bfe542..c76dfde886e5 100644 --- a/packages/firebase_admob/CHANGELOG.md +++ b/packages/firebase_admob/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.6.1 + +* listener on MobileAd shouldn't be final. +* Ad listeners can to be set in or out of Ad initialization. + ## 0.6.0 * Add nonPersonalizedAds option to MobileAdTargetingInfo diff --git a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java index 3b4ecd1f3523..c1e7ee10d9a8 100644 --- a/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java +++ b/packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java @@ -154,6 +154,15 @@ private void callShowAd(int id, MethodCall call, Result result) { result.success(Boolean.TRUE); } + private void callIsAdLoaded(int id, MethodCall call, Result result) { + MobileAd ad = MobileAd.getAdForId(id); + if (ad == null) { + result.error("no_ad_for_id", "isAdLoaded failed, no add exists for id=" + id, null); + return; + } + result.success(ad.status == MobileAd.Status.LOADED ? Boolean.TRUE : Boolean.FALSE); + } + private void callShowRewardedVideoAd(MethodCall call, Result result) { if (rewardedWrapper.getStatus() == RewardedVideoAdWrapper.Status.LOADED) { rewardedWrapper.show(); @@ -208,6 +217,9 @@ public void onMethodCall(MethodCall call, Result result) { case "disposeAd": callDisposeAd(id, call, result); break; + case "isAdLoaded": + callIsAdLoaded(id, call, result); + break; default: result.notImplemented(); } diff --git a/packages/firebase_admob/ios/Classes/FirebaseAdMobPlugin.m b/packages/firebase_admob/ios/Classes/FirebaseAdMobPlugin.m index a49f457b08b6..7ea2ebdcba22 100644 --- a/packages/firebase_admob/ios/Classes/FirebaseAdMobPlugin.m +++ b/packages/firebase_admob/ios/Classes/FirebaseAdMobPlugin.m @@ -210,6 +210,23 @@ - (void)callShowAd:(NSNumber *)mobileAdId result([NSNumber numberWithBool:YES]); } +- (void)callIsAdLoaded:(NSNumber *)mobileAdId + call:(FlutterMethodCall *)call + result:(FlutterResult)result { + FLTMobileAd *ad = [FLTMobileAd getAdForId:mobileAdId]; + if (ad == nil) { + NSString *message = [NSString + stringWithFormat:@"isAdLoaded failed, no ad exists for id=%d", mobileAdId.intValue]; + result([FlutterError errorWithCode:@"no_ad_for_id" message:message details:nil]); + return; + } + if (ad.status == LOADED) { + result([NSNumber numberWithBool:YES]); + } else { + result([NSNumber numberWithBool:NO]); + } +} + - (void)callShowRewardedVideoAd:(FlutterMethodCall *)call result:(FlutterResult)result { if (self.rewardedWrapper.status != FLTRewardedVideoAdStatusLoaded) { result([FlutterError errorWithCode:@"ad_not_loaded" @@ -270,6 +287,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result result:result]; } else if ([call.method isEqualToString:@"showAd"]) { [self callShowAd:mobileAdId call:call result:result]; + } else if ([call.method isEqualToString:@"isAdLoaded"]) { + [self callIsAdLoaded:mobileAdId call:call result:result]; } else if ([call.method isEqualToString:@"disposeAd"]) { [self callDisposeAd:mobileAdId call:call result:result]; } else { diff --git a/packages/firebase_admob/lib/firebase_admob.dart b/packages/firebase_admob/lib/firebase_admob.dart index 8aff656589b0..ba45b6e928ee 100644 --- a/packages/firebase_admob/lib/firebase_admob.dart +++ b/packages/firebase_admob/lib/firebase_admob.dart @@ -190,7 +190,7 @@ abstract class MobileAd { final String adUnitId; /// Called when the status of the ad changes. - final MobileAdListener listener; + MobileAdListener listener; /// An internal id that identifies this mobile ad to the native AdMob plugin. /// @@ -228,6 +228,12 @@ abstract class MobileAd { _allAds[id] = null; return _invokeBooleanMethod("disposeAd", {'id': id}); } + + Future isLoaded() { + return _invokeBooleanMethod("isAdLoaded", { + 'id': id, + }); + } } /// A banner ad for the [FirebaseAdMobPlugin]. diff --git a/packages/firebase_admob/pubspec.yaml b/packages/firebase_admob/pubspec.yaml index 11d2cb914f71..45882be278df 100644 --- a/packages/firebase_admob/pubspec.yaml +++ b/packages/firebase_admob/pubspec.yaml @@ -2,7 +2,7 @@ name: firebase_admob description: Firebase AdMob plugin for Flutter applications. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_admob -version: 0.6.0 +version: 0.6.1 flutter: plugin: