Skip to content

Commit 2636c96

Browse files
committed
refactor(ads): simplify in-article ad loading for demo environment
- Remove demo-specific native ad widget and related logic - Consolidate demo environment ad loading into a single case - Use DemoBannerAdWidget for all in-article ads in demo environment - Remove unnecessary imports and code related to demo environment
1 parent e02c191 commit 2636c96

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

lib/ads/widgets/in_article_ad_loader_widget.dart

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/inlin
1111
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/native_ad.dart';
1212
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/admob_inline_ad_widget.dart';
1313
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/demo_banner_ad_widget.dart';
14-
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/demo_native_ad_widget.dart';
1514
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/local_banner_ad_widget.dart';
1615
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/local_native_ad_widget.dart';
1716
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
18-
import 'package:flutter_news_app_mobile_client_full_source_code/app/config/app_environment.dart';
1917
import 'package:logging/logging.dart';
2018
import 'package:ui_kit/ui_kit.dart';
2119

@@ -159,7 +157,7 @@ class _InArticleAdLoaderWidgetState extends State<InArticleAdLoaderWidget> {
159157
final loadedAd = await widget.adService.getInArticleAd(
160158
adConfig: widget.adConfig,
161159
adThemeStyle: widget.adThemeStyle,
162-
headlineImageStyle: headlineImageStyle, // Pass the headlineImageStyle
160+
headlineImageStyle: headlineImageStyle,
163161
);
164162

165163
if (loadedAd != null) {
@@ -210,33 +208,13 @@ class _InArticleAdLoaderWidgetState extends State<InArticleAdLoaderWidget> {
210208

211209
@override
212210
Widget build(BuildContext context) {
213-
final appEnvironment = context.read<AppBloc>().state.environment;
214211
final headlineImageStyle = context
215212
.read<AppBloc>()
216213
.state
217214
.settings
218215
.feedPreferences
219216
.headlineImageStyle;
220217

221-
// In demo environment, display placeholder ads directly.
222-
if (appEnvironment == AppEnvironment.demo) {
223-
// Determine the ad type from the adConfig's articleAdConfiguration
224-
final adType =
225-
widget.adConfig.articleAdConfiguration.defaultInArticleAdType;
226-
switch (adType) {
227-
case AdType.native:
228-
return DemoNativeAdWidget(headlineImageStyle: headlineImageStyle);
229-
case AdType.banner:
230-
return DemoBannerAdWidget(headlineImageStyle: headlineImageStyle);
231-
case AdType.interstitial:
232-
case AdType.video:
233-
// Interstitial and video ads are not inline, so they won't be
234-
// handled by InArticleAdLoaderWidget. Fallback to a generic placeholder.
235-
return const SizedBox.shrink();
236-
}
237-
}
238-
239-
// For other environments (development, production), proceed with real ad loading.
240218
if (_isLoading) {
241219
return const Padding(
242220
padding: EdgeInsets.symmetric(
@@ -276,6 +254,10 @@ class _InArticleAdLoaderWidgetState extends State<InArticleAdLoaderWidget> {
276254
}
277255
// Fallback for unsupported local ad types or errors
278256
return const SizedBox.shrink();
257+
case AdPlatformType.demo:
258+
// In demo environment, display placeholder ads directly.
259+
// In-article ads are now always banners, so we use DemoBannerAdWidget.
260+
return DemoBannerAdWidget(headlineImageStyle: headlineImageStyle);
279261
}
280262
}
281263
}

0 commit comments

Comments
 (0)