showInterstitial method

Future<ResponseInterstitial> showInterstitial({
  1. String? adUnitId,
})

Returns a ResponseInterstitial which informs about the rewarded dialog.

Implementation

Future<ResponseInterstitial> showInterstitial({String? adUnitId}) async {
  if (isDisabledProgrammatically()) {
    return ResponseInterstitial(
        StatusInterstitial.displayDeniedProgrammatically);
  }

  if (_isInitialized == false) {
    return ResponseInterstitial(StatusInterstitial.notLoadedInitialized);
  }

  if (_intertsitialMap[adUnitId] == null && _intertsitialMap.isEmpty) {
    return ResponseInterstitial(StatusInterstitial.notLoadedAdIdNotSet);
  }

  adUnitId ??= _intertsitialMap.keys.first;

  if (_intertsitialMap[adUnitId]!.isFetching) {
    return ResponseInterstitial(StatusInterstitial.notLoadedButTryingTo);
  }

  final result = await _intertsitialMap[adUnitId]!.showAd();
  _intertsitialMap[adUnitId]!.fetchAd(); // no await
  return result;
}