Skip to content

Commit 735ad25

Browse files
committed
feat(tile): navigate to source/category details
- Added navigation on chip tap - Avoid render current entity chip
1 parent 0147a64 commit 735ad25

File tree

2 files changed

+139
-93
lines changed

2 files changed

+139
-93
lines changed

lib/shared/widgets/headline_tile_image_start.dart

Lines changed: 68 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import 'package:flutter/material.dart';
2+
import 'package:go_router/go_router.dart'; // Added
3+
import 'package:ht_main/entity_details/models/entity_type.dart';
4+
import 'package:ht_main/entity_details/view/entity_details_page.dart'; // Added for Page Arguments
25
import 'package:ht_main/l10n/l10n.dart';
6+
import 'package:ht_main/router/routes.dart'; // Added
37
import 'package:ht_main/shared/constants/app_spacing.dart';
48
import 'package:ht_main/shared/utils/utils.dart'; // Import the new utility
59
import 'package:ht_shared/ht_shared.dart' show Headline;
@@ -15,6 +19,8 @@ class HeadlineTileImageStart extends StatelessWidget {
1519
super.key,
1620
this.onHeadlineTap,
1721
this.trailing,
22+
this.currentContextEntityType,
23+
this.currentContextEntityId,
1824
});
1925

2026
/// The headline data to display.
@@ -26,6 +32,12 @@ class HeadlineTileImageStart extends StatelessWidget {
2632
/// An optional widget to display at the end of the tile.
2733
final Widget? trailing;
2834

35+
/// The type of the entity currently being viewed in detail (e.g., on a category page).
36+
final EntityType? currentContextEntityType;
37+
38+
/// The ID of the entity currently being viewed in detail.
39+
final String? currentContextEntityId;
40+
2941
@override
3042
Widget build(BuildContext context) {
3143
final l10n = context.l10n;
@@ -50,40 +62,39 @@ class HeadlineTileImageStart extends StatelessWidget {
5062
height: 72,
5163
child: ClipRRect(
5264
borderRadius: BorderRadius.circular(AppSpacing.xs),
53-
child:
54-
headline.imageUrl != null
55-
? Image.network(
56-
headline.imageUrl!,
57-
fit: BoxFit.cover,
58-
loadingBuilder: (context, child, loadingProgress) {
59-
if (loadingProgress == null) return child;
60-
return Container(
61-
color: colorScheme.surfaceContainerHighest,
62-
child: const Center(
63-
child: CircularProgressIndicator(
64-
strokeWidth: 2,
65-
),
66-
),
67-
);
68-
},
69-
errorBuilder:
70-
(context, error, stackTrace) => Container(
71-
color: colorScheme.surfaceContainerHighest,
72-
child: Icon(
73-
Icons.broken_image_outlined,
74-
color: colorScheme.onSurfaceVariant,
75-
size: AppSpacing.xl,
76-
),
65+
child: headline.imageUrl != null
66+
? Image.network(
67+
headline.imageUrl!,
68+
fit: BoxFit.cover,
69+
loadingBuilder: (context, child, loadingProgress) {
70+
if (loadingProgress == null) return child;
71+
return Container(
72+
color: colorScheme.surfaceContainerHighest,
73+
child: const Center(
74+
child: CircularProgressIndicator(
75+
strokeWidth: 2,
7776
),
78-
)
79-
: Container(
77+
),
78+
);
79+
},
80+
errorBuilder: (context, error, stackTrace) =>
81+
Container(
8082
color: colorScheme.surfaceContainerHighest,
8183
child: Icon(
82-
Icons.image_not_supported_outlined,
84+
Icons.broken_image_outlined,
8385
color: colorScheme.onSurfaceVariant,
8486
size: AppSpacing.xl,
8587
),
8688
),
89+
)
90+
: Container(
91+
color: colorScheme.surfaceContainerHighest,
92+
child: Icon(
93+
Icons.image_not_supported_outlined,
94+
color: colorScheme.onSurfaceVariant,
95+
size: AppSpacing.xl,
96+
),
97+
),
8798
),
8899
),
89100
const SizedBox(width: AppSpacing.md), // Always add spacing
@@ -105,6 +116,10 @@ class HeadlineTileImageStart extends StatelessWidget {
105116
l10n: l10n,
106117
colorScheme: colorScheme,
107118
textTheme: textTheme,
119+
currentContextEntityType:
120+
currentContextEntityType, // Pass down
121+
currentContextEntityId:
122+
currentContextEntityId, // Pass down
108123
),
109124
],
110125
),
@@ -128,12 +143,16 @@ class _HeadlineMetadataRow extends StatelessWidget {
128143
required this.l10n,
129144
required this.colorScheme,
130145
required this.textTheme,
146+
this.currentContextEntityType,
147+
this.currentContextEntityId,
131148
});
132149

133150
final Headline headline;
134151
final AppLocalizations l10n;
135152
final ColorScheme colorScheme;
136153
final TextTheme textTheme;
154+
final EntityType? currentContextEntityType;
155+
final String? currentContextEntityId;
137156

138157
@override
139158
Widget build(BuildContext context) {
@@ -177,7 +196,10 @@ class _HeadlineMetadataRow extends StatelessWidget {
177196
],
178197
),
179198
),
180-
if (headline.category?.name != null) ...[
199+
// Conditionally render Category Chip
200+
if (headline.category?.name != null &&
201+
!(currentContextEntityType == EntityType.category &&
202+
headline.category!.id == currentContextEntityId)) ...[
181203
if (formattedDate.isNotEmpty)
182204
Padding(
183205
padding: const EdgeInsets.symmetric(
@@ -187,15 +209,12 @@ class _HeadlineMetadataRow extends StatelessWidget {
187209
),
188210
GestureDetector(
189211
onTap: () {
190-
ScaffoldMessenger.of(context)
191-
..hideCurrentSnackBar()
192-
..showSnackBar(
193-
SnackBar(
194-
content: Text(
195-
'Tapped Category: ${headline.category!.name}',
196-
),
197-
),
212+
if (headline.category != null) {
213+
context.push(
214+
Routes.categoryDetails,
215+
extra: EntityDetailsPageArguments(entity: headline.category),
198216
);
217+
}
199218
},
200219
child: Chip(
201220
label: Text(headline.category!.name),
@@ -210,8 +229,14 @@ class _HeadlineMetadataRow extends StatelessWidget {
210229
),
211230
),
212231
],
213-
if (headline.source?.name != null) ...[
214-
if (formattedDate.isNotEmpty || headline.category?.name != null)
232+
// Conditionally render Source Chip
233+
if (headline.source?.name != null &&
234+
!(currentContextEntityType == EntityType.source &&
235+
headline.source!.id == currentContextEntityId)) ...[
236+
if (formattedDate.isNotEmpty ||
237+
(headline.category?.name != null &&
238+
!(currentContextEntityType == EntityType.category &&
239+
headline.category!.id == currentContextEntityId)))
215240
Padding(
216241
padding: const EdgeInsets.symmetric(
217242
horizontal: AppSpacing.xs / 2,
@@ -220,13 +245,12 @@ class _HeadlineMetadataRow extends StatelessWidget {
220245
),
221246
GestureDetector(
222247
onTap: () {
223-
ScaffoldMessenger.of(context)
224-
..hideCurrentSnackBar()
225-
..showSnackBar(
226-
SnackBar(
227-
content: Text('Tapped Source: ${headline.source!.name}'),
228-
),
248+
if (headline.source != null) {
249+
context.push(
250+
Routes.sourceDetails,
251+
extra: EntityDetailsPageArguments(entity: headline.source),
229252
);
253+
}
230254
},
231255
child: Chip(
232256
label: Text(headline.source!.name),

0 commit comments

Comments
 (0)