Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[firebase_admob] Fix firebase_admob issues caused by un-handled exception situations #1807

Closed
wants to merge 12 commits into from
24 changes: 19 additions & 5 deletions packages/firebase_admob/lib/firebase_admob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ abstract class MobileAd {
/// Disposing a banner ad that's been shown removes it from the screen.
/// Interstitial ads can't be programmatically removed from view.
Future<bool> dispose() {
assert(_allAds[id] != null);
// When dispose is called, following assert prevents graceful cleanup of resources
// and occationally causes exception in the plugin which results in dangling
// BannerAd in the app. Hence commenting it for now till better way of handling is
// added by the plugin maintainer.
// assert(_allAds[id] != null);
_allAds[id] = null;
return _invokeBooleanMethod("disposeAd", <String, dynamic>{'id': id});
}
Expand Down Expand Up @@ -515,9 +519,19 @@ class FirebaseAdMob {
}

Future<bool> _invokeBooleanMethod(String method, [dynamic arguments]) async {
final bool result = await FirebaseAdMob.instance._channel.invokeMethod<bool>(
method,
arguments,
);
bool result = false;
try {
result = await FirebaseAdMob.instance._channel.invokeMethod<bool>(
method,
arguments,
);
} on PlatformException catch (e) {
if (e.code == "no_ad_for_id") {
result = false;
return result;
}
rethrow;
}

return result;
}