showConfirmAdDialog method

Future<ResponseInterstitialRewarded> showConfirmAdDialog(
  1. BuildContext context
)

Shows a confirmation dialog, if user confirms the ad is shown. The confirmation dialog is not shown in case the ad is not loaded.

The returned ResponseInterstitialRewarded details the ourtcome.

Call fetchAd before calling this method.

Implementation

Future<ResponseInterstitialRewarded> showConfirmAdDialog(
    BuildContext context) async {
  _log('Checking RewardedInterstitialAd confirm dialog ...');

  /// The completer may indicate failed loading in [fetchAd].
  if (_completer.isCompleted == false) {
    if (_adToShow == null) {
      _log('Aborting, _adToShow is NULL');

      _completer.complete(ResponseInterstitialRewarded(
          StatusInterstitialRewarded.notLoadedGenerally));
    } else {
      _log('Opening RewardedInterstitialAd confirm dialog ...');

      await showDialog<StatusInterstitialRewarded>(
        context: context,
        builder: (_) => DialogConfirmAd(showNoAd: () {
          _log('Opening RewardedInterstitialAd showNoAd()');
          _completer.complete(ResponseInterstitialRewarded(
              StatusInterstitialRewarded.displayDeniedByUser));
        }, showAd: () {
          // _log('Opening RewardedInterstitialAd showAd()');
          _adToShow?.show(
            onUserEarnedReward: (AdWithoutView view, RewardItem rewardItem) {
              // Called on success.
              // The completer is not completed at this point.
              _log('InterstitialRewardedAd onUserEarnedReward');
              _completer.complete(
                ResponseInterstitialRewarded(
                  StatusInterstitialRewarded.displaySuccess,
                  rewardAmount: rewardItem.amount,
                  rewardType: rewardItem.type,
                ),
              );
            },
          );
        }),
      );
    }
  }
  return _completer.future;
}