@@ -7,6 +7,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
77import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_service.dart' ;
88import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart' ;
99import 'package:flutter_news_app_mobile_client_full_source_code/app/config/app_environment.dart' ;
10+ import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_navigator_observer.dart' ;
11+ import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart' ;
1012import 'package:flutter_news_app_mobile_client_full_source_code/app/services/app_status_service.dart' ;
1113import 'package:flutter_news_app_mobile_client_full_source_code/app/services/demo_data_initializer_service.dart' ;
1214import 'package:flutter_news_app_mobile_client_full_source_code/app/services/demo_data_migration_service.dart' ;
@@ -17,6 +19,7 @@ import 'package:flutter_news_app_mobile_client_full_source_code/status/view/view
1719import 'package:go_router/go_router.dart' ;
1820import 'package:kv_storage_service/kv_storage_service.dart' ;
1921import 'package:ui_kit/ui_kit.dart' ;
22+ import 'dart:async' ;
2023
2124class App extends StatelessWidget {
2225 const App ({
@@ -167,7 +170,10 @@ class _AppViewState extends State<_AppView> {
167170 late final ValueNotifier <AppStatus > _statusNotifier;
168171 // The service responsible for automated status checks.
169172 AppStatusService ? _appStatusService;
170- // Removed Dynamic Links subscription
173+ // The observer for handling interstitial ads on route changes.
174+ AdNavigatorObserver ? _adNavigatorObserver;
175+ // Stream subscription for interstitial ad signals from AppBloc.
176+ StreamSubscription <void >? _interstitialAdSubscription;
171177
172178 @override
173179 void initState () {
@@ -185,6 +191,22 @@ class _AppViewState extends State<_AppView> {
185191 environment: widget.environment,
186192 );
187193
194+ // Derive AdThemeStyle from the current theme.
195+ final adThemeStyle = AdThemeStyle .fromTheme (Theme .of (context));
196+
197+ // Initialize AdNavigatorObserver.
198+ _adNavigatorObserver = AdNavigatorObserver (
199+ appBloc: appBloc,
200+ adService: widget.adService,
201+ adThemeStyle: adThemeStyle,
202+ );
203+
204+ // Subscribe to the AppBloc's interstitial ad stream.
205+ _interstitialAdSubscription =
206+ appBloc.showInterstitialAdStream.listen ((_) {
207+ _adNavigatorObserver? .showInterstitialAd ();
208+ });
209+
188210 _router = createRouter (
189211 authStatusNotifier: _statusNotifier,
190212 authenticationRepository: widget.authenticationRepository,
@@ -199,17 +221,19 @@ class _AppViewState extends State<_AppView> {
199221 environment: widget.environment,
200222 adService: widget.adService,
201223 localAdRepository: widget.localAdRepository,
224+ adNavigatorObserver: _adNavigatorObserver! , // Pass the observer
202225 );
203-
204- // Removed Dynamic Link Initialization
205226 }
206227
207228 @override
208229 void dispose () {
209230 _statusNotifier.dispose ();
210231 // Dispose the AppStatusService to cancel timers and remove observers.
211232 _appStatusService? .dispose ();
212- // Removed Dynamic Links subscription cancellation
233+ // Cancel the interstitial ad stream subscription.
234+ _interstitialAdSubscription? .cancel ();
235+ // AdNavigatorObserver does not need explicit dispose here as it's a NavigatorObserver
236+ // and its internal resources are managed by the AdService/AdMob SDK.
213237 super .dispose ();
214238 }
215239
0 commit comments