@@ -90,14 +90,6 @@ class App extends StatelessWidget {
9090 RepositoryProvider .value (value: _kvStorageService),
9191 RepositoryProvider .value (value: _adService),
9292 RepositoryProvider .value (value: _localAdRepository),
93- // Provide the InterstitialAdManager as a RepositoryProvider
94- RepositoryProvider (
95- create: (context) => InterstitialAdManager (
96- appBloc: context.read <AppBloc >(),
97- adService: context.read <AdService >(),
98- ),
99- lazy: false , // Ensure it's created immediately
100- ),
10193 ],
10294 child: MultiBlocProvider (
10395 providers: [
@@ -121,6 +113,16 @@ class App extends StatelessWidget {
121113 authenticationRepository: context.read <AuthRepository >(),
122114 ),
123115 ),
116+ // Provide the InterstitialAdManager as a RepositoryProvider
117+ // it depends on the state managed by AppBloc. Therefore,
118+ // so it must be created after AppBloc is available.
119+ RepositoryProvider (
120+ create: (context) => InterstitialAdManager (
121+ appBloc: context.read <AppBloc >(),
122+ adService: context.read <AdService >(),
123+ ),
124+ lazy: false , // Ensure it's created immediately
125+ ),
124126 ],
125127 child: _AppView (
126128 authenticationRepository: _authenticationRepository,
@@ -220,8 +222,6 @@ class _AppViewState extends State<_AppView> {
220222 _statusNotifier.dispose ();
221223 // Dispose the AppStatusService to cancel timers and remove observers.
222224 _appStatusService? .dispose ();
223- // Dispose the InterstitialAdManager
224- context.read <InterstitialAdManager >().dispose ();
225225 super .dispose ();
226226 }
227227
0 commit comments