Skip to content

Commit b4cd7b4

Browse files
committed
refactor(headlines-feed): improve ad loading and display mechanism
- Replace AdFeedItem with AdPlaceholder to decouple ad loading from feed item generation - Introduce AdLoaderWidget to handle ad loading and display - Update imports to use AdService and AdPlaceholder instead of direct ad models - Modify HeadlinesFeedFetchRequested event to not include adThemeStyle
1 parent 967782d commit b4cd7b4

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/headlines-feed/view/headlines_feed_page.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import 'package:core/core.dart';
55
import 'package:flutter/material.dart';
66
import 'package:flutter_bloc/flutter_bloc.dart';
77
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/account_bloc.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/ad_service.dart';
9+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_placeholder.dart';
910
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart';
10-
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/widgets.dart';
11+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/ad_loader_widget.dart';
1112
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
1213
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/bloc/headlines_feed_bloc.dart';
1314
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
@@ -54,10 +55,10 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
5455
WidgetsBinding.instance.addPostFrameCallback((_) {
5556
if (mounted) {
5657
context.read<HeadlinesFeedBloc>().add(
57-
HeadlinesFeedFetchRequested(
58-
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
59-
),
60-
);
58+
HeadlinesFeedFetchRequested(
59+
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
60+
),
61+
);
6162
}
6263
});
6364
}
@@ -317,8 +318,12 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
317318
);
318319
}
319320
return tile;
320-
} else if (item is AdFeedItem) {
321-
return AdFeedItemWidget(adFeedItem: item);
321+
} else if (item is AdPlaceholder) {
322+
return AdLoaderWidget(
323+
adPlaceholder: item,
324+
adService: context.read<AdService>(),
325+
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
326+
);
322327
} else if (item is CallToActionItem) {
323328
return CallToActionDecoratorWidget(
324329
item: item,

0 commit comments

Comments
 (0)