showInterstitialRewarded method

Future<ResponseInterstitialRewarded> showInterstitialRewarded(
  1. BuildContext context,
  2. Widget confirmDialog, {
  3. String? adUnitId,
})

Returns a ResponseInterstitialRewarded which informs about the rewarded dialog.

Implementation

Future<ResponseInterstitialRewarded> showInterstitialRewarded(
    BuildContext context, Widget confirmDialog,
    {String? adUnitId}) async {
  if (isDisabledProgrammatically()) {
    return ResponseInterstitialRewarded(
        StatusInterstitialRewarded.displayDeniedProgrammatically);
  }

  if (_isInitialized == false) {
    return ResponseInterstitialRewarded(
        StatusInterstitialRewarded.notLoadedInitialized);
  }

  if (_interstitialRewardedMap[adUnitId] == null &&
      _interstitialRewardedMap.isEmpty) {
    return ResponseInterstitialRewarded(
        StatusInterstitialRewarded.notLoadedAdIdNotSet);
  }

  adUnitId ??= _interstitialRewardedMap.keys.first;

  if (_interstitialRewardedMap[adUnitId]!.isFetching) {
    return ResponseInterstitialRewarded(
        StatusInterstitialRewarded.notLoadedButTryingTo);
  }

  final result = await _interstitialRewardedMap[adUnitId]!
      .showConfirmAdDialog(confirmDialog, context);
  _interstitialRewardedMap[adUnitId]!.fetchAd(); // no await
  return result;
}