Skip to content

Commit cec3c1c

Browse files
committed
refactor(ads): improve ad loading widget separation of concerns
- Wrap successfully loaded ads in AdFeedItem model - Use AdFeedItemWidget for rendering instead of AdmobNativeAdWidget - This change prepares for future integration of non-AdMob ads - Enhances code maintainability and flexibility
1 parent 460b4b2 commit cec3c1c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/ads/widgets/ad_loader_widget.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_cache_service.dart';
44
import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_service.dart';
5+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_feed_item.dart';
56
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_placeholder.dart';
67
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart';
78
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/native_ad.dart';
8-
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/admob_native_ad_widget.dart';
9+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/ad_feed_item_widget.dart';
910
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/placeholder_ad_widget.dart';
1011
import 'package:logging/logging.dart';
1112
import 'package:ui_kit/ui_kit.dart';
@@ -139,9 +140,16 @@ class _AdLoaderWidgetState extends State<AdLoaderWidget> {
139140
// Show a placeholder or error message if ad loading failed.
140141
return const PlaceholderAdWidget();
141142
} else {
142-
// If an ad is successfully loaded, display it using the appropriate widget.
143-
// The AdmobNativeAdWidget is responsible for rendering the native ad object.
144-
return AdmobNativeAdWidget(nativeAd: _loadedAd!);
143+
// If an ad is successfully loaded, wrap it in an AdFeedItem
144+
// and pass it to the AdFeedItemWidget for rendering.
145+
// This improves separation of concerns, as AdLoaderWidget is now
146+
// only responsible for loading, not rendering logic.
147+
return AdFeedItemWidget(
148+
adFeedItem: AdFeedItem(
149+
id: widget.adPlaceholder.id,
150+
nativeAd: _loadedAd!,
151+
),
152+
);
145153
}
146154
}
147155
}

0 commit comments

Comments
 (0)