Skip to content

Commit efbce2a

Browse files
committed
feat(ads): add demo environment interstitial ad mock
- Add conditional logic to show placeholder interstitial ad in demo environment - Create new DemoInterstitialAdDialog widget for demo environment - Remove unused PlaceholderAdWidget
1 parent 9ba72b6 commit efbce2a

File tree

3 files changed

+18
-55
lines changed

3 files changed

+18
-55
lines changed

lib/ads/ad_navigator_observer.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_service.d
66
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart';
77
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/widgets.dart';
88
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
9+
import 'package:flutter_news_app_mobile_client_full_source_code/app/config/app_environment.dart';
910
import 'package:google_mobile_ads/google_mobile_ads.dart' as admob;
1011
import 'package:logging/logging.dart';
1112

@@ -124,8 +125,21 @@ class AdNavigatorObserver extends NavigatorObserver {
124125

125126
/// Requests and shows an interstitial ad if conditions are met.
126127
Future<void> _showInterstitialAd() async {
127-
final remoteConfig = appStateProvider().remoteConfig;
128+
final appState = appStateProvider();
129+
final appEnvironment = appState.environment;
130+
final remoteConfig = appState.remoteConfig;
131+
132+
// In demo environment, display a placeholder interstitial ad directly.
133+
if (appEnvironment == AppEnvironment.demo) {
134+
_logger.info('Demo environment: Showing placeholder interstitial ad.');
135+
await showDialog<void>(
136+
context: navigator!.context,
137+
builder: (context) => const DemoInterstitialAdDialog(),
138+
);
139+
return;
140+
}
128141

142+
// For other environments (development, production), proceed with real ad loading.
129143
// This is a secondary check. The primary check is in _handlePageTransition.
130144
if (remoteConfig == null || !remoteConfig.adConfig.enabled) {
131145
_logger.info('Interstitial ads disabled or remote config not available.');

lib/ads/widgets/placeholder_ad_widget.dart

Lines changed: 0 additions & 53 deletions
This file was deleted.

lib/ads/widgets/widgets.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export 'admob_inline_ad_widget.dart';
2+
export 'demo_banner_ad_widget.dart';
3+
export 'demo_interstitial_ad_dialog.dart';
4+
export 'demo_native_ad_widget.dart';
25
export 'feed_ad_loader_widget.dart';
36
export 'in_article_ad_loader_widget.dart';
47
export 'local_banner_ad_widget.dart';
58
export 'local_interstitial_ad_dialog.dart';
69
export 'local_native_ad_widget.dart';
7-
export 'placeholder_ad_widget.dart';

0 commit comments

Comments
 (0)