Skip to content

Commit 7684dcd

Browse files
committed
feat(ads): add environment check for demo ad platform
- Add AppEnvironment dependency to AdService - Implement checks to skip ad loads when RemoteConfig specifies AdPlatformType.demo but the app is not in the demo environment - Log warnings when skipping ad loads due to environment mismatch
1 parent 3fff693 commit 7684dcd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/ads/ad_service.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_th
44
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/inline_ad.dart';
55
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/interstitial_ad.dart';
66
import 'package:logging/logging.dart';
7+
import 'package:flutter_news_app_mobile_client_full_source_code/app/config/app_environment.dart';
78

89
/// {@template ad_service}
910
/// A service responsible for managing and providing ads to the application.
@@ -20,11 +21,14 @@ class AdService {
2021
/// These providers will be used to load ads from specific ad networks.
2122
AdService({
2223
required Map<AdPlatformType, AdProvider> adProviders,
24+
required AppEnvironment environment,
2325
Logger? logger,
2426
}) : _adProviders = adProviders,
27+
_environment = environment,
2528
_logger = logger ?? Logger('AdService');
2629

2730
final Map<AdPlatformType, AdProvider> _adProviders;
31+
final AppEnvironment _environment;
2832
final Logger _logger;
2933

3034
// Configurable retry parameters for ad loading.
@@ -135,6 +139,18 @@ class AdService {
135139
}
136140

137141
final primaryAdPlatform = adConfig.primaryAdPlatform;
142+
143+
// If RemoteConfig specifies AdPlatformType.demo but the app is not in demo environment,
144+
// log a warning and skip ad load.
145+
if (primaryAdPlatform == AdPlatformType.demo &&
146+
_environment != AppEnvironment.demo) {
147+
_logger.warning(
148+
'AdService: RemoteConfig specifies AdPlatformType.demo as primary '
149+
'ad platform, but app is not in demo environment. Skipping interstitial ad load.',
150+
);
151+
return null;
152+
}
153+
138154
final adProvider = _adProviders[primaryAdPlatform];
139155

140156
if (adProvider == null) {
@@ -264,6 +280,18 @@ class AdService {
264280
}
265281

266282
final primaryAdPlatform = adConfig.primaryAdPlatform;
283+
284+
// If RemoteConfig specifies AdPlatformType.demo but the app is not in demo environment,
285+
// log a warning and skip ad load.
286+
if (primaryAdPlatform == AdPlatformType.demo &&
287+
_environment != AppEnvironment.demo) {
288+
_logger.warning(
289+
'AdService: RemoteConfig specifies AdPlatformType.demo as primary '
290+
'ad platform, but app is not in demo environment. Skipping inline ad load.',
291+
);
292+
return null;
293+
}
294+
267295
final adProvider = _adProviders[primaryAdPlatform];
268296

269297
if (adProvider == null) {

0 commit comments

Comments
 (0)