Created
April 7, 2022 00:17
-
-
Save luizmarcus/fc4177e0396f82ad56f6de4a1ea7ffee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InterstitialAd? _interstitialAd; | |
void _createInterstitialAd() { | |
InterstitialAd.load( | |
adUnitId: Constants.ADMOB_TEST_INTERSTITIAL_ID, | |
request: const AdRequest(), | |
adLoadCallback: InterstitialAdLoadCallback( | |
onAdLoaded: (InterstitialAd ad) { | |
print('$ad carregado'); | |
_interstitialAd = ad; | |
}, | |
onAdFailedToLoad: (LoadAdError error) { | |
print('InterstitialAd falhou ao carregar $error.'); | |
_interstitialAd = null; | |
_createInterstitialAd(); | |
}, | |
)); | |
} | |
void _showInterstitialAd() { | |
if (_interstitialAd == null) { | |
print('Aviso: tentou mostrar o intersticial antes de ser carregado.'); | |
return; | |
} | |
_interstitialAd!.fullScreenContentCallback = FullScreenContentCallback( | |
onAdShowedFullScreenContent: (InterstitialAd ad) => | |
print('ad onAdShowedFullScreenContent.'), | |
onAdDismissedFullScreenContent: (InterstitialAd ad) { | |
print('$ad onAdDismissedFullScreenContent.'); | |
ad.dispose(); | |
_createInterstitialAd(); | |
}, | |
onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) { | |
print('$ad onAdFailedToShowFullScreenContent: $error'); | |
ad.dispose(); | |
_createInterstitialAd(); | |
}, | |
); | |
_interstitialAd!.show(); | |
_interstitialAd = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment