1- //
2- // ignore_for_file: lines_longer_than_80_chars
3-
41import 'package:core/core.dart' ;
52import 'package:flutter/material.dart' ;
63import 'package:flutter_bloc/flutter_bloc.dart' ;
7- import 'package:flutter_news_app_mobile_client_full_source_code/ads/interstitial_ad_manager.dart' ;
84import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_placeholder.dart' ;
95import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart' ;
106import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/feed_ad_loader_widget.dart' ;
@@ -237,23 +233,6 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
237233 );
238234 }
239235
240- Future <void > onHeadlineTap (Headline headline) async {
241- // Await for the ad to be shown and dismissed.
242- await context
243- .read <InterstitialAdManager >()
244- .onPotentialAdTrigger ();
245-
246- // Check if the widget is still in the tree before navigating.
247- if (! context.mounted) return ;
248-
249- // Proceed with navigation after the ad is closed.
250- await context.pushNamed (
251- Routes .articleDetailsName,
252- pathParameters: {'id' : headline.id},
253- extra: headline,
254- );
255- }
256-
257236 return RefreshIndicator (
258237 onRefresh: () async {
259238 context.read <HeadlinesFeedBloc >().add (
@@ -272,15 +251,16 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
272251 ? state.feedItems.length + 1
273252 : state.feedItems.length,
274253 separatorBuilder: (context, index) {
275- if (index < state.feedItems.length - 1 ) {
276- final currentItem = state.feedItems[index];
277- final nextItem = state.feedItems[index + 1 ];
278- // Adjust spacing around any decorator or ad
279- if (currentItem is ! Headline || nextItem is ! Headline ) {
280- return const SizedBox (height: AppSpacing .md);
281- }
254+ if (index >= state.feedItems.length - 1 ) {
255+ return const SizedBox .shrink ();
256+ }
257+ final currentItem = state.feedItems[index];
258+ final nextItem = state.feedItems[index + 1 ];
259+
260+ if (currentItem is ! Headline || nextItem is ! Headline ) {
261+ return const SizedBox (height: AppSpacing .md);
282262 }
283- return const SizedBox (height: AppSpacing .lg );
263+ return const SizedBox (height: AppSpacing .sm );
284264 },
285265 itemBuilder: (context, index) {
286266 if (index >= state.feedItems.length) {
@@ -305,17 +285,29 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
305285 case HeadlineImageStyle .hidden:
306286 tile = HeadlineTileTextOnly (
307287 headline: item,
308- onHeadlineTap: () => onHeadlineTap (item),
288+ onHeadlineTap: () =>
289+ HeadlineTapHandler .handleHeadlineTap (
290+ context,
291+ item,
292+ ),
309293 );
310294 case HeadlineImageStyle .smallThumbnail:
311295 tile = HeadlineTileImageStart (
312296 headline: item,
313- onHeadlineTap: () => onHeadlineTap (item),
297+ onHeadlineTap: () =>
298+ HeadlineTapHandler .handleHeadlineTap (
299+ context,
300+ item,
301+ ),
314302 );
315303 case HeadlineImageStyle .largeThumbnail:
316304 tile = HeadlineTileImageTop (
317305 headline: item,
318- onHeadlineTap: () => onHeadlineTap (item),
306+ onHeadlineTap: () =>
307+ HeadlineTapHandler .handleHeadlineTap (
308+ context,
309+ item,
310+ ),
319311 );
320312 }
321313 return tile;
0 commit comments