Skip to content

Commit

Permalink
DebugPrint:
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Malandruccolo committed Dec 8, 2023
1 parent 6884784 commit d5fbcad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// ignore_for_file: public_member_api_docs
import 'package:app_open_example/app_open_ad_manager.dart';
import 'package:flutter/cupertino.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

/// Listens for app foreground events and shows app open ads.
Expand All @@ -29,7 +30,7 @@ class AppLifecycleReactor {
}

void _onAppStateChanged(AppState appState) {
print('New AppState state: $appState');
debugPrint('New AppState state: $appState');
if (appState == AppState.foreground) {
appOpenAdManager.showAdIfAvailable();
}
Expand Down
17 changes: 9 additions & 8 deletions samples/admob/app_open_example/lib/app_open_ad_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// ignore_for_file: public_member_api_docs

import 'package:flutter/cupertino.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'dart:io' show Platform;

Expand All @@ -40,12 +41,12 @@ class AppOpenAdManager {
request: const AdRequest(),
adLoadCallback: AppOpenAdLoadCallback(
onAdLoaded: (ad) {
print('$ad loaded');
debugPrint('$ad loaded');
_appOpenLoadTime = DateTime.now();
_appOpenAd = ad;
},
onAdFailedToLoad: (error) {
print('AppOpenAd failed to load: $error');
debugPrint('AppOpenAd failed to load: $error');
},
),
);
Expand All @@ -62,16 +63,16 @@ class AppOpenAdManager {
/// new ad.
void showAdIfAvailable() {
if (!isAdAvailable) {
print('Tried to show ad before available.');
debugPrint('Tried to show ad before available.');
loadAd();
return;
}
if (_isShowingAd) {
print('Tried to show ad while already showing an ad.');
debugPrint('Tried to show ad while already showing an ad.');
return;
}
if (DateTime.now().subtract(maxCacheDuration).isAfter(_appOpenLoadTime!)) {
print('Maximum cache duration exceeded. Loading another ad.');
debugPrint('Maximum cache duration exceeded. Loading another ad.');
_appOpenAd!.dispose();
_appOpenAd = null;
loadAd();
Expand All @@ -81,16 +82,16 @@ class AppOpenAdManager {
_appOpenAd!.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (ad) {
_isShowingAd = true;
print('$ad onAdShowedFullScreenContent');
debugPrint('$ad onAdShowedFullScreenContent');
},
onAdFailedToShowFullScreenContent: (ad, error) {
print('$ad onAdFailedToShowFullScreenContent: $error');
debugPrint('$ad onAdFailedToShowFullScreenContent: $error');
_isShowingAd = false;
ad.dispose();
_appOpenAd = null;
},
onAdDismissedFullScreenContent: (ad) {
print('$ad onAdDismissedFullScreenContent');
debugPrint('$ad onAdDismissedFullScreenContent');
_isShowingAd = false;
ad.dispose();
_appOpenAd = null;
Expand Down

0 comments on commit d5fbcad

Please sign in to comment.