@@ -26,9 +26,9 @@ class InterstitialAdManager {
2626 required AppBloc appBloc,
2727 required AdService adService,
2828 Logger ? logger,
29- }) : _appBloc = appBloc,
30- _adService = adService,
31- _logger = logger ?? Logger ('InterstitialAdManager' ) {
29+ }) : _appBloc = appBloc,
30+ _adService = adService,
31+ _logger = logger ?? Logger ('InterstitialAdManager' ) {
3232 // Listen to the AppBloc stream to react to state changes.
3333 _appBlocSubscription = _appBloc.stream.listen (_onAppStateChanged);
3434 // Initialize with the current state.
@@ -67,9 +67,7 @@ class InterstitialAdManager {
6767 // If the ad config or user role has changed, update internal state
6868 // and potentially pre-load a new ad.
6969 if (newAdConfig != _adConfig || newUserRole != _userRole) {
70- _logger.info (
71- 'Ad config or user role changed. Updating internal state.' ,
72- );
70+ _logger.info ('Ad config or user role changed. Updating internal state.' );
7371 _adConfig = newAdConfig;
7472 _userRole = newUserRole;
7573 // A config change might mean we need to load an ad now.
@@ -102,21 +100,23 @@ class InterstitialAdManager {
102100 final brightness = appState.themeMode == ThemeMode .system
103101 ? SchedulerBinding .instance.window.platformBrightness
104102 : (appState.themeMode == ThemeMode .dark
105- ? Brightness .dark
106- : Brightness .light);
103+ ? Brightness .dark
104+ : Brightness .light);
107105
108106 // Create a ThemeData instance from the AppState's settings.
109107 // This allows us to derive AdThemeStyle without a BuildContext.
110108 final themeData = brightness == Brightness .light
111109 ? lightTheme (
112110 scheme: appState.flexScheme,
113- appTextScaleFactor: appState.settings.displaySettings.textScaleFactor,
111+ appTextScaleFactor:
112+ appState.settings.displaySettings.textScaleFactor,
114113 appFontWeight: appState.settings.displaySettings.fontWeight,
115114 fontFamily: appState.settings.displaySettings.fontFamily,
116115 )
117116 : darkTheme (
118117 scheme: appState.flexScheme,
119- appTextScaleFactor: appState.settings.displaySettings.textScaleFactor,
118+ appTextScaleFactor:
119+ appState.settings.displaySettings.textScaleFactor,
120120 appFontWeight: appState.settings.displaySettings.fontWeight,
121121 fontFamily: appState.settings.displaySettings.fontFamily,
122122 );
@@ -170,7 +170,8 @@ class InterstitialAdManager {
170170 if (requiredTransitions > 0 && _transitionCount >= requiredTransitions) {
171171 _logger.info ('Transition count meets threshold. Attempting to show ad.' );
172172 await _showAd (context);
173- _transitionCount = 0 ; // Reset counter after showing (or attempting to show)
173+ _transitionCount =
174+ 0 ; // Reset counter after showing (or attempting to show)
174175 } else {
175176 _logger.info (
176177 'Transition count ($_transitionCount ) has not met threshold ($requiredTransitions ).' ,
@@ -181,7 +182,9 @@ class InterstitialAdManager {
181182 /// Shows the pre-loaded interstitial ad.
182183 Future <void > _showAd (BuildContext context) async {
183184 if (_preloadedAd == null ) {
184- _logger.warning ('Show ad called, but no ad is pre-loaded. Pre-loading now.' );
185+ _logger.warning (
186+ 'Show ad called, but no ad is pre-loaded. Pre-loading now.' ,
187+ );
185188 // Attempt a last-minute load if no ad is ready.
186189 await _maybePreloadAd (_appBloc.state);
187190 if (_preloadedAd == null ) {
@@ -198,8 +201,10 @@ class InterstitialAdManager {
198201 case AdPlatformType .admob:
199202 await _showAdMobAd (adToShow);
200203 case AdPlatformType .local:
204+ // ignore: use_build_context_synchronously
201205 await _showLocalAd (context, adToShow);
202206 case AdPlatformType .demo:
207+ // ignore: use_build_context_synchronously
203208 await _showDemoAd (context);
204209 }
205210 } catch (e, s) {
@@ -208,35 +213,35 @@ class InterstitialAdManager {
208213 // After the ad is shown or fails to show, dispose of it and
209214 // start pre-loading the next one for the next opportunity.
210215 _disposePreloadedAd (); // Ensure the ad object is disposed
211- _maybePreloadAd (_appBloc.state);
216+ unawaited ( _maybePreloadAd (_appBloc.state) );
212217 }
213218 }
214219
215220 Future <void > _showAdMobAd (InterstitialAd ad) async {
216221 if (ad.adObject is ! admob.InterstitialAd ) return ;
217222 final admobAd = ad.adObject as admob.InterstitialAd
218-
219- ..fullScreenContentCallback = admob.FullScreenContentCallback (
220- onAdShowedFullScreenContent: (ad) =>
221- _logger.info ('AdMob ad showed full screen.' ),
222- onAdDismissedFullScreenContent: (ad) {
223- _logger.info ('AdMob ad dismissed.' );
224- ad.dispose ();
225- },
226- onAdFailedToShowFullScreenContent: (ad, error) {
227- _logger.severe ('AdMob ad failed to show: $error ' );
228- ad.dispose ();
229- },
230- );
223+ ..fullScreenContentCallback = admob.FullScreenContentCallback (
224+ onAdShowedFullScreenContent: (ad) =>
225+ _logger.info ('AdMob ad showed full screen.' ),
226+ onAdDismissedFullScreenContent: (ad) {
227+ _logger.info ('AdMob ad dismissed.' );
228+ ad.dispose ();
229+ },
230+ onAdFailedToShowFullScreenContent: (ad, error) {
231+ _logger.severe ('AdMob ad failed to show: $error ' );
232+ ad.dispose ();
233+ },
234+ );
231235 await admobAd.show ();
232236 }
233237
234238 Future <void > _showLocalAd (BuildContext context, InterstitialAd ad) async {
235239 if (ad.adObject is ! LocalInterstitialAd ) return ;
236240 await showDialog <void >(
237241 context: context,
238- builder: (_) =>
239- LocalInterstitialAdDialog (localInterstitialAd: ad.adObject as LocalInterstitialAd ),
242+ builder: (_) => LocalInterstitialAdDialog (
243+ localInterstitialAd: ad.adObject as LocalInterstitialAd ,
244+ ),
240245 );
241246 }
242247
0 commit comments