Skip to content

Commit 5c2a57f

Browse files
committed
refactor(headlines-search): update ad loading logic in headlines search
- Replace AppBloc state for ad configuration with remoteConfig - Add null check for adConfig and handle null case - Update AdLoaderWidget constructor to use adConfig instead of imageStyle
1 parent a382066 commit 5c2a57f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/headlines-search/view/headlines_search_page.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,22 +346,26 @@ class _HeadlinesSearchViewState extends State<_HeadlinesSearchView> {
346346
} else if (feedItem is Country) {
347347
return CountryItemWidget(country: feedItem);
348348
} else if (feedItem is AdPlaceholder) {
349-
// Retrieve the user's preferred headline image style from the AppBloc.
350-
// This is the single source of truth for this setting.
351-
final imageStyle = context
352-
.watch<AppBloc>()
349+
// Access the AppBloc to get the remoteConfig for ads.
350+
final adConfig = context
351+
.read<AppBloc>()
353352
.state
354-
.settings
355-
.feedPreferences
356-
.headlineImageStyle;
353+
.remoteConfig
354+
?.adConfig;
355+
356+
// Ensure adConfig is not null before building the AdLoaderWidget.
357+
if (adConfig == null) {
358+
// Return an empty widget or a placeholder if adConfig is not available.
359+
return const SizedBox.shrink();
360+
}
357361

358362
return AdLoaderWidget(
359363
adPlaceholder: feedItem,
360364
adService: context.read<AdService>(),
361365
adThemeStyle: AdThemeStyle.fromTheme(
362366
Theme.of(context),
363367
),
364-
imageStyle: imageStyle,
368+
adConfig: adConfig,
365369
);
366370
}
367371
return const SizedBox.shrink();

0 commit comments

Comments
 (0)