Skip to content

Commit

Permalink
async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Malandruccolo committed May 3, 2024
1 parent 178a670 commit 544288f
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions samples/admob/interstitial_example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ class InterstitialExampleState extends State<InterstitialExample> {
}

/// Loads an interstitial ad.
void _loadAd() {
void _loadAd() async {
// Only load an ad if the Mobile Ads SDK has gathered consent aligned with
// the app's configured messages.
_consentManager.canRequestAds().then((response) {
if (!response) {
return;
}
});
var canRequestAds = await _consentManager.canRequestAds();
if (!canRequestAds) {
return;
}

InterstitialAd.load(
adUnitId: _adUnitId,
Expand Down Expand Up @@ -232,21 +231,20 @@ class InterstitialExampleState extends State<InterstitialExample> {

/// Initialize the Mobile Ads SDK if the SDK has gathered consent aligned with
/// the app's configured messages.
void _initializeMobileAdsSDK() {
void _initializeMobileAdsSDK() async {
if (_isMobileAdsInitializeCalled) {
return;
}

_consentManager.canRequestAds().then((response) {
if (response) {
_isMobileAdsInitializeCalled = true;
var canRequestAds = await _consentManager.canRequestAds();
if (canRequestAds) {
_isMobileAdsInitializeCalled = true;

// Initialize the Mobile Ads SDK.
MobileAds.instance.initialize();
// Load an ad.
_loadAd();
}
});
// Initialize the Mobile Ads SDK.
MobileAds.instance.initialize();
// Load an ad.
_loadAd();
}
}

@override
Expand Down

0 comments on commit 544288f

Please sign in to comment.