Skip to content

Commit cbec1de

Browse files
committed
refactor(ads): expand in-article ad loader to support multiple ad types
- Update InArticleAdLoaderWidget to handle different ad types and providers - Add support for Admob inline ads, local banner ads, and local native ads - Introduce provider-specific ad rendering widgets - Remove unused AdFeedItem model and widget
1 parent e718c95 commit cbec1de

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lib/ads/widgets/in_article_ad_loader_widget.dart

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import 'package:flutter/material.dart';
55
import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_cache_service.dart';
66
import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_service.dart';
77
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart';
8-
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_feed_item.dart';
8+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/banner_ad.dart';
99
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/inline_ad.dart';
10-
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/ad_feed_item_widget.dart';
10+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/native_ad.dart';
11+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/admob_inline_ad_widget.dart';
12+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/local_banner_ad_widget.dart';
13+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/local_native_ad_widget.dart';
1114
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/placeholder_ad_widget.dart';
1215
import 'package:logging/logging.dart';
1316
import 'package:ui_kit/ui_kit.dart';
@@ -210,12 +213,20 @@ class _InArticleAdLoaderWidgetState extends State<InArticleAdLoaderWidget> {
210213
} else if (_hasError || _loadedAd == null) {
211214
return const PlaceholderAdWidget();
212215
} else {
213-
return AdFeedItemWidget(
214-
adFeedItem: AdFeedItem(
215-
id: widget.slotConfiguration.slotType.name,
216-
inlineAd: _loadedAd!,
217-
),
218-
);
216+
// If an ad is successfully loaded, dispatch to the appropriate
217+
// provider-specific widget for rendering.
218+
switch (_loadedAd!.provider) {
219+
case AdPlatformType.admob:
220+
return AdmobInlineAdWidget(inlineAd: _loadedAd!);
221+
case AdPlatformType.local:
222+
if (_loadedAd is NativeAd && _loadedAd!.adObject is LocalNativeAd) {
223+
return LocalNativeAdWidget(localNativeAd: _loadedAd!.adObject as LocalNativeAd);
224+
} else if (_loadedAd is BannerAd && _loadedAd!.adObject is LocalBannerAd) {
225+
return LocalBannerAdWidget(localBannerAd: _loadedAd!.adObject as LocalBannerAd);
226+
}
227+
// Fallback for unsupported local ad types or errors
228+
return const PlaceholderAdWidget();
229+
}
219230
}
220231
}
221232
}

0 commit comments

Comments
 (0)