From ddc01ba0fcb7a9472752f82043512ecb1a31bf01 Mon Sep 17 00:00:00 2001 From: Tanzil Zubair Bin Zaman Date: Thu, 9 Mar 2023 10:03:33 +0600 Subject: [PATCH 1/4] [feature] added callbacks --- .flutter-plugins | 2 +- .flutter-plugins-dependencies | 2 +- README.md | 8 ++-- example/lib/main.dart | 2 +- lib/src/managed_interstitial_ad_queue.dart | 50 ++++++++-------------- lib/src/managed_rewarded_ad_queue.dart | 50 ++++++++-------------- 6 files changed, 44 insertions(+), 70 deletions(-) diff --git a/.flutter-plugins b/.flutter-plugins index 87230e9..a6d00da 100644 --- a/.flutter-plugins +++ b/.flutter-plugins @@ -1,2 +1,2 @@ # This is a generated file; do not edit or check into version control. -google_mobile_ads=/Users/tanzilzubairbinzaman/Flutter/.pub-cache/hosted/pub.dartlang.org/google_mobile_ads-2.3.0/ +google_mobile_ads=/Users/makduman/.pub-cache/hosted/pub.dev/google_mobile_ads-2.4.0/ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 0701c7f..ac08f98 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"google_mobile_ads","path":"/Users/tanzilzubairbinzaman/Flutter/.pub-cache/hosted/pub.dartlang.org/google_mobile_ads-2.3.0/","native_build":true,"dependencies":[]}],"android":[{"name":"google_mobile_ads","path":"/Users/tanzilzubairbinzaman/Flutter/.pub-cache/hosted/pub.dartlang.org/google_mobile_ads-2.3.0/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"google_mobile_ads","dependencies":[]}],"date_created":"2023-02-03 11:45:31.898293","version":"3.3.10"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"google_mobile_ads","path":"/Users/makduman/.pub-cache/hosted/pub.dev/google_mobile_ads-2.4.0/","native_build":true,"dependencies":[]}],"android":[{"name":"google_mobile_ads","path":"/Users/makduman/.pub-cache/hosted/pub.dev/google_mobile_ads-2.4.0/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"google_mobile_ads","dependencies":[]}],"date_created":"2023-10-06 06:53:19.477305","version":"3.7.12"} \ No newline at end of file diff --git a/README.md b/README.md index 77e42c9..ba4559c 100644 --- a/README.md +++ b/README.md @@ -97,10 +97,10 @@ ManagedAppOpenAd ad = MobileAdsManager.instance.getManagedAppOpenAd()!; ad.showAppOpenAd(); ``` -App Open Ads can be shown based in a probabilistic method (for example, when an App Open Ad should be shown 60% of the time a user opens the app) by passing the probability, ranging from `0.0` to `1.0` to `AppOpenAdInitializer.loadChance`. +App Open Ads can be shown based on a probabilistic method (for example, when an App Open Ad should be shown 60% of the time a user opens the app) by passing the probability, ranging from `0.0` to `1.0` to `AppOpenAdInitializer.loadChance`. **Note:** -- Depending on what `ManagedAppOpenAd.loadChance` is, the `ManagedOpenAd` may be null. Passing no value results in a `loadChance` of `1.0`, which guarantees the `ManagedOpenAd` will always be loaded. +- Depending on what `ManagedAppOpenAd.loadChance` is, the `ManagedAppOpenAd` may be null. Passing no value results in a `loadChance` of `1.0`, which guarantees the `ManagedAppOpenAd` will always be loaded. ```dart // Initializing the App Open Ad with an AppOpenAdInitializer configuration @@ -135,7 +135,7 @@ ad.dispose(); ``` ## Interstitial Ads -Interstitial Ads are interacted with through a fully self-managing queue instance of `ManagedInterstitialAdQueue`, similar to Rewarded Ads. The queue contains a number of `InterstitialAd`s determined by `InterstitialAdInitializer.count`, and automatically disposes an Ad once its shown, and loads another in its place. +Interstitial Ads are interacted with through a fully self-managing queue instance of `ManagedInterstitialAdQueue`, similar to Rewarded Ads. The queue contains a number of `InterstitialAd`s determined by `InterstitialAdInitializer.count`, and automatically disposes an Ad once it's shown, and loads another in its place. In this way, a small number of ads are always preloaded and ready to be shown, cutting down on waiting times. The queue can be initialized by providing an instance of `InterstitialAdInitializer` to `initializeSDK` during SDK initialization, Alternatively, they can also be initialized at any time by calling @@ -209,7 +209,7 @@ queue?.dispose(); - Calling `dispose` **does not dispose an individual ad**, and rather disposes the entire queue of ads for that Ad Unit ID, as well as the ManagedInterstitialAdQueue instance. Individual ads will be automatically disposed once they're shown, or if they ever fail to load. ## Rewarded Ads -Rewarded Ads are interacted with through a fully self-managing queue instance of `ManagedRewardedAdQueue`, similar to Interstitial Ads. The queue contains a number of `RewardedAd`s determined by `RewardedAdInitializer.count`, and automatically disposes an Ad once its shown, and loads another in its place. +Rewarded Ads are interacted with through a fully self-managing queue instance of `ManagedRewardedAdQueue`, similar to Interstitial Ads. The queue contains a number of `RewardedAd`s determined by `RewardedAdInitializer.count`, and automatically disposes an Ad once it's shown, and loads another in its place. In this way, a small number of ads are always preloaded and ready to be shown, cutting down on waiting times. The queue can be initialized by providing an instance of `RewardedAdInitializer` to `initializeSDK` during SDK initialization, Alternatively, they can also be initialized at any time by calling diff --git a/example/lib/main.dart b/example/lib/main.dart index dc81548..ea3c413 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -90,7 +90,7 @@ class RewardedExample extends StatelessWidget { MobileAdsManager.instance .getManagedRewardedAdQueue(adUnitId: '') ?.showRewardedAd( - onUserEarnedReward: (AdWithoutView ad, RewardItem reward) { + callback: () { // Reward user }, ); diff --git a/lib/src/managed_interstitial_ad_queue.dart b/lib/src/managed_interstitial_ad_queue.dart index bfb1751..65fe4e6 100644 --- a/lib/src/managed_interstitial_ad_queue.dart +++ b/lib/src/managed_interstitial_ad_queue.dart @@ -62,10 +62,7 @@ class ManagedInterstitialAdQueue { Future _initializeInterstitialAdQueue() async { try { await Future.wait( - [ - for (int i = 0; i <= _interstitialAdInitializer.count; i++) - _addInterstitialAd() - ], + [for (int i = 0; i <= _interstitialAdInitializer.count; i++) _addInterstitialAd()], ); } catch (e) { /// Rethrowing the error, to be caught by an enclosing try-catch block @@ -77,7 +74,7 @@ class ManagedInterstitialAdQueue { /// Shows an interstitial ad, based on the [showChance], automatically /// reloading the queue after the ad is shown, or doing nothing at all /// if the ad is not shown (due to [showChance]) - void showInterstitialAd({double showChance = 1.0}) { + void showInterstitialAd({double showChance = 1.0, void Function()? callback}) { assert( showChance >= 0.0 && showChance <= 1.0, 'showChance must be a double between 0.0 and 1.0, both inclusive', @@ -99,32 +96,28 @@ class ManagedInterstitialAdQueue { adsInQueue = _queue.length; /// Reloading the queue - _addInterstitialAd(); + _addInterstitialAd(callback: callback); } + } else { + callback?.call(); } } /// Adds another interstitial ad to the internal managed queue, /// provided it does not exceed [_interstitialAdInitializer.count] elements /// in the queue - Future _addInterstitialAd() async { + Future _addInterstitialAd({void Function()? callback}) async { /// Configuring the callbacks for the ad, and combining them with the user /// provided ones - final FullScreenContentCallback fullScreenContentCallback = - FullScreenContentCallback( - onAdShowedFullScreenContent: _interstitialAdInitializer - .fullScreenContentCallback?.onAdShowedFullScreenContent, - onAdClicked: - _interstitialAdInitializer.fullScreenContentCallback?.onAdClicked, - onAdImpression: - _interstitialAdInitializer.fullScreenContentCallback?.onAdImpression, - onAdWillDismissFullScreenContent: _interstitialAdInitializer - .fullScreenContentCallback?.onAdWillDismissFullScreenContent, + final FullScreenContentCallback fullScreenContentCallback = FullScreenContentCallback( + onAdShowedFullScreenContent: _interstitialAdInitializer.fullScreenContentCallback?.onAdShowedFullScreenContent, + onAdClicked: _interstitialAdInitializer.fullScreenContentCallback?.onAdClicked, + onAdImpression: _interstitialAdInitializer.fullScreenContentCallback?.onAdImpression, + onAdWillDismissFullScreenContent: _interstitialAdInitializer.fullScreenContentCallback?.onAdWillDismissFullScreenContent, onAdDismissedFullScreenContent: (InterstitialAd ad) { /// Calling the user provided function - _interstitialAdInitializer - .fullScreenContentCallback?.onAdDismissedFullScreenContent - ?.call(ad); + _interstitialAdInitializer.fullScreenContentCallback?.onAdDismissedFullScreenContent?.call(ad); + callback?.call(); /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() @@ -133,12 +126,10 @@ class ManagedInterstitialAdQueue { ad.dispose(); } catch (_) {} }, - onAdFailedToShowFullScreenContent: - (InterstitialAd ad, AdError error) async { + onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) async { /// Calling the user provided function - _interstitialAdInitializer - .fullScreenContentCallback?.onAdFailedToShowFullScreenContent - ?.call(ad, error); + _interstitialAdInitializer.fullScreenContentCallback?.onAdFailedToShowFullScreenContent?.call(ad, error); + callback?.call(); /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() @@ -170,8 +161,7 @@ class ManagedInterstitialAdQueue { adsInQueue = _queue.length; /// Calling the user provided function - _interstitialAdInitializer.interstitialAdLoadCallback - ?.onAdLoaded(ad); + _interstitialAdInitializer.interstitialAdLoadCallback?.onAdLoaded(ad); } else { /// Disposing the ad as it was an excess, probably a result /// of showing and requesting ad loads in rapid succession. @@ -180,8 +170,7 @@ class ManagedInterstitialAdQueue { }, onAdFailedToLoad: (LoadAdError error) async { /// Calling the user provided function - _interstitialAdInitializer.interstitialAdLoadCallback - ?.onAdFailedToLoad(error); + _interstitialAdInitializer.interstitialAdLoadCallback?.onAdFailedToLoad(error); /// Retrying the load on fail, via recursion, up to 3 times before cancelling _retryLoadCount += 1; @@ -225,8 +214,7 @@ class ManagedInterstitialAdQueue { /// Removing this instance of [ManagedInterstitialAdQueue] from the internal /// list of instantiated [ManagedInterstitialAdQueue] maintained by /// [MobileAdsManager.instance._managedInterstitialAdQueueList] - MobileAdsManager.instance._managedInterstitialAdQueueList - .removeWhere((ManagedInterstitialAdQueue queue) { + MobileAdsManager.instance._managedInterstitialAdQueueList.removeWhere((ManagedInterstitialAdQueue queue) { /// Matching Ad Unit Ids to determine which queue to remove, as there /// can only be one queue per Ad Unit Id return queue.adUnitId == adUnitId; diff --git a/lib/src/managed_rewarded_ad_queue.dart b/lib/src/managed_rewarded_ad_queue.dart index 2fd0cad..fef9991 100644 --- a/lib/src/managed_rewarded_ad_queue.dart +++ b/lib/src/managed_rewarded_ad_queue.dart @@ -62,10 +62,7 @@ class ManagedRewardedAdQueue { Future _initializeRewardedAdQueue() async { try { await Future.wait( - [ - for (int i = 0; i <= _rewardedAdInitializer.count; i++) - _addRewardedAd() - ], + [for (int i = 0; i <= _rewardedAdInitializer.count; i++) _addRewardedAd()], ); } catch (e) { /// Rethrowing the error, to be caught by an enclosing try-catch block @@ -79,11 +76,7 @@ class ManagedRewardedAdQueue { /// if the ad is not shown (due to [showChance]) void showRewardedAd({ double showChance = 1.0, - required void Function( - AdWithoutView ad, - RewardItem reward, - ) - onUserEarnedReward, + void Function()? callback, }) { assert( showChance >= 0.0 && showChance <= 1.0, @@ -99,39 +92,35 @@ class ManagedRewardedAdQueue { /// exhausted before refills are completed if (_queue.isNotEmpty == true) { /// Showing the ad - _queue.removeFirst().show(onUserEarnedReward: onUserEarnedReward); + _queue.removeFirst().show(onUserEarnedReward: (_, __) => callback?.call()); /// Updating the public count of how many ads are /// currently available in the queue adsInQueue = _queue.length; /// Reloading the queue - _addRewardedAd(); + _addRewardedAd(callback: callback); } + } else { + callback?.call(); } } /// Adds another rewarded ad to the internal managed queue, /// provided it does not exceed [_rewardedAdInitializer.count] elements /// in the queue - Future _addRewardedAd() async { + Future _addRewardedAd({void Function()? callback}) async { /// Configuring the callbacks for the ad, and combining them with the user /// provided ones - final FullScreenContentCallback fullScreenContentCallback = - FullScreenContentCallback( - onAdShowedFullScreenContent: _rewardedAdInitializer - .fullScreenContentCallback?.onAdShowedFullScreenContent, - onAdClicked: - _rewardedAdInitializer.fullScreenContentCallback?.onAdClicked, - onAdImpression: - _rewardedAdInitializer.fullScreenContentCallback?.onAdImpression, - onAdWillDismissFullScreenContent: _rewardedAdInitializer - .fullScreenContentCallback?.onAdWillDismissFullScreenContent, + final FullScreenContentCallback fullScreenContentCallback = FullScreenContentCallback( + onAdShowedFullScreenContent: _rewardedAdInitializer.fullScreenContentCallback?.onAdShowedFullScreenContent, + onAdClicked: _rewardedAdInitializer.fullScreenContentCallback?.onAdClicked, + onAdImpression: _rewardedAdInitializer.fullScreenContentCallback?.onAdImpression, + onAdWillDismissFullScreenContent: _rewardedAdInitializer.fullScreenContentCallback?.onAdWillDismissFullScreenContent, onAdDismissedFullScreenContent: (RewardedAd ad) { /// Calling the user provided function - _rewardedAdInitializer - .fullScreenContentCallback?.onAdDismissedFullScreenContent - ?.call(ad); + _rewardedAdInitializer.fullScreenContentCallback?.onAdDismissedFullScreenContent?.call(ad); + callback?.call(); /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() @@ -142,9 +131,8 @@ class ManagedRewardedAdQueue { }, onAdFailedToShowFullScreenContent: (RewardedAd ad, AdError error) async { /// Calling the user provided function - _rewardedAdInitializer - .fullScreenContentCallback?.onAdFailedToShowFullScreenContent - ?.call(ad, error); + _rewardedAdInitializer.fullScreenContentCallback?.onAdFailedToShowFullScreenContent?.call(ad, error); + callback?.call(); /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() @@ -185,8 +173,7 @@ class ManagedRewardedAdQueue { }, onAdFailedToLoad: (LoadAdError error) async { /// Calling the user provided function - _rewardedAdInitializer.rewardedAdLoadCallback - ?.onAdFailedToLoad(error); + _rewardedAdInitializer.rewardedAdLoadCallback?.onAdFailedToLoad(error); /// Retrying the load on fail, via recursion, up to 3 times before cancelling _retryLoadCount += 1; @@ -230,8 +217,7 @@ class ManagedRewardedAdQueue { /// Removing this instance of [ManagedRewardedAdQueue] from the internal /// list of instantiated [ManagedRewardedAdQueue] maintained by /// [MobileAdsManager.instance._managedRewardedAdQueueList] - MobileAdsManager.instance._managedRewardedAdQueueList - .removeWhere((ManagedRewardedAdQueue queue) { + MobileAdsManager.instance._managedRewardedAdQueueList.removeWhere((ManagedRewardedAdQueue queue) { /// Matching Ad Unit Ids to determine which queue to remove, as there /// can only be one queue per Ad Unit Id return queue.adUnitId == adUnitId; From 7510817523cc3a9b972a99811ebabc7251ede609 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 6 Oct 2023 08:34:28 +0300 Subject: [PATCH 2/4] [bug-fix] callback fixed --- lib/src/managed_interstitial_ad_queue.dart | 49 ++++++++++++++++++---- lib/src/managed_rewarded_ad_queue.dart | 8 ++-- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/lib/src/managed_interstitial_ad_queue.dart b/lib/src/managed_interstitial_ad_queue.dart index 65fe4e6..6d43018 100644 --- a/lib/src/managed_interstitial_ad_queue.dart +++ b/lib/src/managed_interstitial_ad_queue.dart @@ -74,7 +74,7 @@ class ManagedInterstitialAdQueue { /// Shows an interstitial ad, based on the [showChance], automatically /// reloading the queue after the ad is shown, or doing nothing at all /// if the ad is not shown (due to [showChance]) - void showInterstitialAd({double showChance = 1.0, void Function()? callback}) { + void showInterstitialAd({double showChance = 1.0, void Function()? callback}) { assert( showChance >= 0.0 && showChance <= 1.0, 'showChance must be a double between 0.0 and 1.0, both inclusive', @@ -89,6 +89,41 @@ class ManagedInterstitialAdQueue { /// exhausted before refills are completed if (_queue.isNotEmpty == true) { /// Showing the ad + _queue.first.fullScreenContentCallback = FullScreenContentCallback( + onAdShowedFullScreenContent: _interstitialAdInitializer.fullScreenContentCallback?.onAdShowedFullScreenContent, + onAdClicked: _interstitialAdInitializer.fullScreenContentCallback?.onAdClicked, + onAdImpression: _interstitialAdInitializer.fullScreenContentCallback?.onAdImpression, + onAdWillDismissFullScreenContent: (InterstitialAd ad) { + callback?.call(); + + _interstitialAdInitializer.fullScreenContentCallback?.onAdWillDismissFullScreenContent?.call(ad); + }, + onAdDismissedFullScreenContent: (InterstitialAd ad) { + /// Calling the user provided function + _interstitialAdInitializer.fullScreenContentCallback?.onAdDismissedFullScreenContent?.call(ad); + callback?.call(); + + /// Disposing the ad. The code is inside a try block to guard + /// against developers who accidentally include a call to .dispose() + /// in their code + try { + ad.dispose(); + } catch (_) {} + }, + onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) async { + /// Calling the user provided function + _interstitialAdInitializer.fullScreenContentCallback?.onAdFailedToShowFullScreenContent?.call(ad, error); + callback?.call(); + + /// Disposing the ad. The code is inside a try block to guard + /// against developers who accidentally include a call to .dispose() + /// in [_interstitialAdInitializer.fullScreenContentCallback?.onAdFailedToShowFullScreenContent] + try { + ad.dispose(); + } catch (_) {} + }, + ); + _queue.removeFirst().show(); /// Updating the public count of how many ads are @@ -96,7 +131,7 @@ class ManagedInterstitialAdQueue { adsInQueue = _queue.length; /// Reloading the queue - _addInterstitialAd(callback: callback); + _addInterstitialAd(); } } else { callback?.call(); @@ -106,19 +141,19 @@ class ManagedInterstitialAdQueue { /// Adds another interstitial ad to the internal managed queue, /// provided it does not exceed [_interstitialAdInitializer.count] elements /// in the queue - Future _addInterstitialAd({void Function()? callback}) async { + Future _addInterstitialAd() async { /// Configuring the callbacks for the ad, and combining them with the user /// provided ones final FullScreenContentCallback fullScreenContentCallback = FullScreenContentCallback( onAdShowedFullScreenContent: _interstitialAdInitializer.fullScreenContentCallback?.onAdShowedFullScreenContent, onAdClicked: _interstitialAdInitializer.fullScreenContentCallback?.onAdClicked, onAdImpression: _interstitialAdInitializer.fullScreenContentCallback?.onAdImpression, - onAdWillDismissFullScreenContent: _interstitialAdInitializer.fullScreenContentCallback?.onAdWillDismissFullScreenContent, + onAdWillDismissFullScreenContent: (InterstitialAd ad) { + _interstitialAdInitializer.fullScreenContentCallback?.onAdWillDismissFullScreenContent?.call(ad); + }, onAdDismissedFullScreenContent: (InterstitialAd ad) { /// Calling the user provided function _interstitialAdInitializer.fullScreenContentCallback?.onAdDismissedFullScreenContent?.call(ad); - callback?.call(); - /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() /// in their code @@ -129,7 +164,7 @@ class ManagedInterstitialAdQueue { onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) async { /// Calling the user provided function _interstitialAdInitializer.fullScreenContentCallback?.onAdFailedToShowFullScreenContent?.call(ad, error); - callback?.call(); + /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() diff --git a/lib/src/managed_rewarded_ad_queue.dart b/lib/src/managed_rewarded_ad_queue.dart index fef9991..e24e905 100644 --- a/lib/src/managed_rewarded_ad_queue.dart +++ b/lib/src/managed_rewarded_ad_queue.dart @@ -99,7 +99,7 @@ class ManagedRewardedAdQueue { adsInQueue = _queue.length; /// Reloading the queue - _addRewardedAd(callback: callback); + _addRewardedAd(); } } else { callback?.call(); @@ -109,7 +109,7 @@ class ManagedRewardedAdQueue { /// Adds another rewarded ad to the internal managed queue, /// provided it does not exceed [_rewardedAdInitializer.count] elements /// in the queue - Future _addRewardedAd({void Function()? callback}) async { + Future _addRewardedAd() async { /// Configuring the callbacks for the ad, and combining them with the user /// provided ones final FullScreenContentCallback fullScreenContentCallback = FullScreenContentCallback( @@ -120,7 +120,7 @@ class ManagedRewardedAdQueue { onAdDismissedFullScreenContent: (RewardedAd ad) { /// Calling the user provided function _rewardedAdInitializer.fullScreenContentCallback?.onAdDismissedFullScreenContent?.call(ad); - callback?.call(); + /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() @@ -132,8 +132,6 @@ class ManagedRewardedAdQueue { onAdFailedToShowFullScreenContent: (RewardedAd ad, AdError error) async { /// Calling the user provided function _rewardedAdInitializer.fullScreenContentCallback?.onAdFailedToShowFullScreenContent?.call(ad, error); - callback?.call(); - /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() /// in [_rewardedAdInitializer.fullScreenContentCallback?.onAdFailedToShowFullScreenContent] From 2b1e2362615689a4202b942f5d9b586456064ff0 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 10 Oct 2023 22:57:26 +0300 Subject: [PATCH 3/4] [bug-fix] failed to show ad fixed --- lib/src/managed_interstitial_ad_queue.dart | 3 +++ lib/src/managed_rewarded_ad_queue.dart | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/src/managed_interstitial_ad_queue.dart b/lib/src/managed_interstitial_ad_queue.dart index 6d43018..f41e26e 100644 --- a/lib/src/managed_interstitial_ad_queue.dart +++ b/lib/src/managed_interstitial_ad_queue.dart @@ -133,6 +133,9 @@ class ManagedInterstitialAdQueue { /// Reloading the queue _addInterstitialAd(); } + else { + callback?.call(); + } } else { callback?.call(); } diff --git a/lib/src/managed_rewarded_ad_queue.dart b/lib/src/managed_rewarded_ad_queue.dart index e24e905..36756d8 100644 --- a/lib/src/managed_rewarded_ad_queue.dart +++ b/lib/src/managed_rewarded_ad_queue.dart @@ -101,6 +101,9 @@ class ManagedRewardedAdQueue { /// Reloading the queue _addRewardedAd(); } + else { + callback?.call(); + } } else { callback?.call(); } From 076453462c12d68bfe2305b3b17b5ad4040aaa88 Mon Sep 17 00:00:00 2001 From: mehmetakdumann Date: Tue, 30 Jan 2024 01:15:46 +0300 Subject: [PATCH 4/4] [feature] hasError field for show interstitial & rewarded ads --- example/lib/main.dart | 2 +- lib/src/managed_interstitial_ad_queue.dart | 12 ++++++------ lib/src/managed_rewarded_ad_queue.dart | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index ea3c413..3b2b10a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -90,7 +90,7 @@ class RewardedExample extends StatelessWidget { MobileAdsManager.instance .getManagedRewardedAdQueue(adUnitId: '') ?.showRewardedAd( - callback: () { + callback: (bool hasError) { // Reward user }, ); diff --git a/lib/src/managed_interstitial_ad_queue.dart b/lib/src/managed_interstitial_ad_queue.dart index f41e26e..482dbbd 100644 --- a/lib/src/managed_interstitial_ad_queue.dart +++ b/lib/src/managed_interstitial_ad_queue.dart @@ -74,7 +74,7 @@ class ManagedInterstitialAdQueue { /// Shows an interstitial ad, based on the [showChance], automatically /// reloading the queue after the ad is shown, or doing nothing at all /// if the ad is not shown (due to [showChance]) - void showInterstitialAd({double showChance = 1.0, void Function()? callback}) { + void showInterstitialAd({double showChance = 1.0, void Function(bool hasError)? callback}) { assert( showChance >= 0.0 && showChance <= 1.0, 'showChance must be a double between 0.0 and 1.0, both inclusive', @@ -94,14 +94,14 @@ class ManagedInterstitialAdQueue { onAdClicked: _interstitialAdInitializer.fullScreenContentCallback?.onAdClicked, onAdImpression: _interstitialAdInitializer.fullScreenContentCallback?.onAdImpression, onAdWillDismissFullScreenContent: (InterstitialAd ad) { - callback?.call(); + callback?.call(false); _interstitialAdInitializer.fullScreenContentCallback?.onAdWillDismissFullScreenContent?.call(ad); }, onAdDismissedFullScreenContent: (InterstitialAd ad) { /// Calling the user provided function _interstitialAdInitializer.fullScreenContentCallback?.onAdDismissedFullScreenContent?.call(ad); - callback?.call(); + callback?.call(false); /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() @@ -113,7 +113,7 @@ class ManagedInterstitialAdQueue { onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) async { /// Calling the user provided function _interstitialAdInitializer.fullScreenContentCallback?.onAdFailedToShowFullScreenContent?.call(ad, error); - callback?.call(); + callback?.call(true); /// Disposing the ad. The code is inside a try block to guard /// against developers who accidentally include a call to .dispose() @@ -134,10 +134,10 @@ class ManagedInterstitialAdQueue { _addInterstitialAd(); } else { - callback?.call(); + callback?.call(true); } } else { - callback?.call(); + callback?.call(true); } } diff --git a/lib/src/managed_rewarded_ad_queue.dart b/lib/src/managed_rewarded_ad_queue.dart index 36756d8..5ecec85 100644 --- a/lib/src/managed_rewarded_ad_queue.dart +++ b/lib/src/managed_rewarded_ad_queue.dart @@ -76,7 +76,7 @@ class ManagedRewardedAdQueue { /// if the ad is not shown (due to [showChance]) void showRewardedAd({ double showChance = 1.0, - void Function()? callback, + void Function(bool hasError)? callback, }) { assert( showChance >= 0.0 && showChance <= 1.0, @@ -92,7 +92,7 @@ class ManagedRewardedAdQueue { /// exhausted before refills are completed if (_queue.isNotEmpty == true) { /// Showing the ad - _queue.removeFirst().show(onUserEarnedReward: (_, __) => callback?.call()); + _queue.removeFirst().show(onUserEarnedReward: (_, __) => callback?.call(false)); /// Updating the public count of how many ads are /// currently available in the queue @@ -102,10 +102,10 @@ class ManagedRewardedAdQueue { _addRewardedAd(); } else { - callback?.call(); + callback?.call(true); } } else { - callback?.call(); + callback?.call(true); } }