Skip to content

Commit e02c191

Browse files
committed
refactor(ads): move demo environment ad logic to correct platform type
- Remove app environment check from build method - Remove unused import of AppEnvironment - Move demo environment ad logic to AdPlatformType case statement - Simplify ad loading logic for non-demo environments
1 parent 34c9762 commit e02c191

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

lib/ads/widgets/feed_ad_loader_widget.dart

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/demo
1616
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/local_banner_ad_widget.dart';
1717
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/local_native_ad_widget.dart';
1818
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
19-
import 'package:flutter_news_app_mobile_client_full_source_code/app/config/app_environment.dart';
2019
import 'package:logging/logging.dart';
2120
import 'package:ui_kit/ui_kit.dart';
2221

@@ -263,30 +262,13 @@ class _FeedAdLoaderWidgetState extends State<FeedAdLoaderWidget> {
263262

264263
@override
265264
Widget build(BuildContext context) {
266-
final appEnvironment = context.read<AppBloc>().state.environment;
267265
final headlineImageStyle = context
268266
.read<AppBloc>()
269267
.state
270268
.settings
271269
.feedPreferences
272270
.headlineImageStyle;
273271

274-
// In demo environment, display placeholder ads directly.
275-
if (appEnvironment == AppEnvironment.demo) {
276-
switch (widget.adPlaceholder.adType) {
277-
case AdType.native:
278-
return DemoNativeAdWidget(headlineImageStyle: headlineImageStyle);
279-
case AdType.banner:
280-
return DemoBannerAdWidget(headlineImageStyle: headlineImageStyle);
281-
case AdType.interstitial:
282-
case AdType.video:
283-
// Interstitial and video ads are not inline, so they won't be
284-
// handled by FeedAdLoaderWidget. Fallback to a generic placeholder.
285-
return const SizedBox.shrink();
286-
}
287-
}
288-
289-
// For other environments (development, production), proceed with real ad loading.
290272
if (_isLoading) {
291273
// Show a shimmer or loading indicator while the ad is being loaded.
292274
return const Padding(
@@ -302,7 +284,7 @@ class _FeedAdLoaderWidgetState extends State<FeedAdLoaderWidget> {
302284
),
303285
);
304286
} else if (_hasError || _loadedAd == null) {
305-
// Fallback for unsupported local ad types or errors
287+
// Fallback for unsupported ad types or errors
306288
return const SizedBox.shrink();
307289
} else {
308290
// If an ad is successfully loaded, dispatch to the appropriate
@@ -328,6 +310,19 @@ class _FeedAdLoaderWidgetState extends State<FeedAdLoaderWidget> {
328310
}
329311
// Fallback for unsupported local ad types or errors
330312
return const SizedBox.shrink();
313+
case AdPlatformType.demo:
314+
// In demo environment, display placeholder ads directly.
315+
switch (widget.adPlaceholder.adType) {
316+
case AdType.native:
317+
return DemoNativeAdWidget(headlineImageStyle: headlineImageStyle);
318+
case AdType.banner:
319+
return DemoBannerAdWidget(headlineImageStyle: headlineImageStyle);
320+
case AdType.interstitial:
321+
case AdType.video:
322+
// Interstitial and video ads are not inline, so they won't be
323+
// handled by FeedAdLoaderWidget. Fallback to a generic placeholder.
324+
return const SizedBox.shrink();
325+
}
331326
}
332327
}
333328
}

0 commit comments

Comments
 (0)