showBeforeNavigation method

void showBeforeNavigation(
  1. VoidCallback onComplete
)

Shows an interstitial before navigation when the threshold is met. Counter is only reset if an ad was actually ready to show. If no ad is cached, the user navigates freely and a background load starts.

Implementation

void showBeforeNavigation(VoidCallback onComplete) {
  if (!_isSafeToOperate || !hasInterstitial || _isProUser()) {
    onComplete();
    return;
  }

  // Check if incrementing would meet the threshold
  if (_screenCount + 1 >= _config.interstitialAfter) {
    if (_interstitialHandler?.isLoaded == true) {
      // Ad is ready — consume the threshold and show
      _screenCount = 0;
      _pendingNavCallback = onComplete;
      _triggerInterstitialIfReady();
    } else {
      // Ad not ready — let user navigate freely, start a background load.
      // Counter is NOT reset so the next navigation will retry immediately.
      onComplete();
      _ensureInterstitialLoading();
    }
  } else {
    _screenCount++;
    onComplete();
  }
}