Skip to content

Commit 9fe2e38

Browse files
committed
refactor(headline-details): improve ad and similar headlines layout
- Wrap ad and continue reading button in Column widget - Adjust padding and spacing for better consistency - Hide similar headlines section when empty - Simplify layout for better readability and performance
1 parent 6f543df commit 9fe2e38

File tree

1 file changed

+83
-77
lines changed

1 file changed

+83
-77
lines changed

lib/headline-details/view/headline_details_page.dart

Lines changed: 83 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,19 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
357357
if (aboveContinueReadingSlot != null) {
358358
slivers.add(
359359
SliverToBoxAdapter(
360-
child: Padding(
361-
padding: horizontalPadding.copyWith(top: AppSpacing.lg),
362-
child: InArticleAdLoaderWidget(
363-
slotConfiguration: aboveContinueReadingSlot,
364-
adService: adService,
365-
adThemeStyle: adThemeStyle,
366-
adConfig: adConfig,
367-
),
360+
child: Column(
361+
children: [
362+
const SizedBox(height: AppSpacing.lg),
363+
Padding(
364+
padding: horizontalPadding,
365+
child: InArticleAdLoaderWidget(
366+
slotConfiguration: aboveContinueReadingSlot,
367+
adService: adService,
368+
adThemeStyle: adThemeStyle,
369+
adConfig: adConfig,
370+
),
371+
),
372+
],
368373
),
369374
),
370375
);
@@ -374,36 +379,33 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
374379
slivers.addAll([
375380
if (headline.url.isNotEmpty)
376381
SliverPadding(
377-
padding: horizontalPadding.copyWith(
378-
top: AppSpacing.lg, // Adjusted for symmetry
379-
bottom: AppSpacing.lg, // Adjusted for symmetry
380-
),
382+
padding: horizontalPadding,
381383
sliver: SliverToBoxAdapter(
382-
child: ElevatedButton.icon(
383-
icon: const Icon(Icons.open_in_new_outlined),
384-
onPressed: () async {
385-
await launchUrlString(headline.url);
386-
},
387-
label: Text(l10n.headlineDetailsContinueReadingButton),
388-
style: ElevatedButton.styleFrom(
389-
padding: const EdgeInsets.symmetric(
390-
horizontal: AppSpacing.lg,
391-
vertical: AppSpacing.md,
392-
),
393-
textStyle: textTheme.labelLarge?.copyWith(
394-
fontWeight: FontWeight.bold,
384+
child: Column(
385+
children: [
386+
const SizedBox(height: AppSpacing.lg),
387+
ElevatedButton.icon(
388+
icon: const Icon(Icons.open_in_new_outlined),
389+
onPressed: () async {
390+
await launchUrlString(headline.url);
391+
},
392+
label: Text(l10n.headlineDetailsContinueReadingButton),
393+
style: ElevatedButton.styleFrom(
394+
padding: const EdgeInsets.symmetric(
395+
horizontal: AppSpacing.lg,
396+
vertical: AppSpacing.md,
397+
),
398+
textStyle: textTheme.labelLarge?.copyWith(
399+
fontWeight: FontWeight.bold,
400+
),
401+
),
395402
),
396-
),
403+
],
397404
),
398405
),
399406
),
400-
if (headline.url.isEmpty) // Ensure bottom padding
401-
const SliverPadding(
402-
padding: EdgeInsets.only(
403-
bottom: AppSpacing.lg,
404-
), // Adjusted for symmetry
405-
sliver: SliverToBoxAdapter(child: SizedBox.shrink()),
406-
),
407+
if (headline.url.isEmpty)
408+
const SliverToBoxAdapter(child: SizedBox.shrink()),
407409
]);
408410

409411
// Add ad below continue reading button if configured
@@ -423,42 +425,60 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
423425
if (belowContinueReadingSlot != null) {
424426
slivers.add(
425427
SliverToBoxAdapter(
426-
child: Padding(
427-
padding: horizontalPadding.copyWith(
428-
top: AppSpacing.lg,
429-
), // Adjusted for symmetry
430-
child: InArticleAdLoaderWidget(
431-
slotConfiguration: belowContinueReadingSlot,
432-
adService: adService,
433-
adThemeStyle: adThemeStyle,
434-
adConfig: adConfig,
435-
),
428+
child: Column(
429+
children: [
430+
const SizedBox(height: AppSpacing.lg),
431+
Padding(
432+
padding: horizontalPadding,
433+
child: InArticleAdLoaderWidget(
434+
slotConfiguration: belowContinueReadingSlot,
435+
adService: adService,
436+
adThemeStyle: adThemeStyle,
437+
adConfig: adConfig,
438+
),
439+
),
440+
],
436441
),
437442
),
438443
);
439444
}
440445
}
441446

442-
slivers.addAll([
443-
SliverPadding(
444-
padding: horizontalPadding,
445-
sliver: SliverToBoxAdapter(
446-
child: Padding(
447-
padding: const EdgeInsets.only(
448-
top: AppSpacing.xl, // Adjusted for consistent separation
449-
bottom: AppSpacing.md,
450-
),
451-
child: Text(
452-
l10n.similarHeadlinesSectionTitle,
453-
style: textTheme.titleLarge?.copyWith(
454-
fontWeight: FontWeight.bold,
447+
slivers.add(
448+
BlocBuilder<SimilarHeadlinesBloc, SimilarHeadlinesState>(
449+
builder: (context, state) {
450+
if (state is SimilarHeadlinesLoaded &&
451+
state.similarHeadlines.isEmpty ||
452+
state is SimilarHeadlinesEmpty) {
453+
return const SliverToBoxAdapter(child: SizedBox.shrink());
454+
}
455+
return SliverMainAxisGroup(
456+
slivers: [
457+
const SliverToBoxAdapter(
458+
child: SizedBox(height: AppSpacing.xl),
455459
),
456-
),
457-
),
458-
),
460+
SliverPadding(
461+
padding: horizontalPadding,
462+
sliver: SliverToBoxAdapter(
463+
child: Padding(
464+
padding: const EdgeInsets.only(
465+
bottom: AppSpacing.md,
466+
),
467+
child: Text(
468+
l10n.similarHeadlinesSectionTitle,
469+
style: textTheme.titleLarge?.copyWith(
470+
fontWeight: FontWeight.bold,
471+
),
472+
),
473+
),
474+
),
475+
),
476+
_buildSimilarHeadlinesSection(context, horizontalPadding),
477+
],
478+
);
479+
},
459480
),
460-
_buildSimilarHeadlinesSection(context, horizontalPadding),
461-
]);
481+
);
462482

463483
return CustomScrollView(slivers: slivers);
464484
}
@@ -594,7 +614,6 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
594614
BuildContext context,
595615
EdgeInsets hPadding,
596616
) {
597-
final l10n = AppLocalizationsX(context).l10n;
598617
final theme = Theme.of(context);
599618
final textTheme = theme.textTheme;
600619
final colorScheme = theme.colorScheme;
@@ -622,21 +641,8 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
622641
),
623642
),
624643
),
625-
SimilarHeadlinesEmpty() => SliverToBoxAdapter(
626-
child: Padding(
627-
padding: hPadding.copyWith(
628-
top: AppSpacing.md,
629-
bottom: AppSpacing.xl,
630-
),
631-
child: Text(
632-
l10n.similarHeadlinesEmpty,
633-
textAlign: TextAlign.center,
634-
style: textTheme.bodyLarge?.copyWith(
635-
color: colorScheme.onSurfaceVariant,
636-
),
637-
),
638-
),
639-
),
644+
SimilarHeadlinesEmpty() =>
645+
const SliverToBoxAdapter(child: SizedBox.shrink()),
640646
final SimilarHeadlinesLoaded loadedState => SliverPadding(
641647
padding: hPadding.copyWith(bottom: AppSpacing.xxl),
642648
sliver: SliverList.separated(

0 commit comments

Comments
 (0)