1
1
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
2
5
import 'package:ht_main/l10n/l10n.dart' ;
6
+ import 'package:ht_main/router/routes.dart' ; // Added
3
7
import 'package:ht_main/shared/constants/app_spacing.dart' ;
4
8
import 'package:ht_main/shared/utils/utils.dart' ; // Import the new utility
5
9
import 'package:ht_shared/ht_shared.dart' show Headline;
@@ -15,6 +19,8 @@ class HeadlineTileImageStart extends StatelessWidget {
15
19
super .key,
16
20
this .onHeadlineTap,
17
21
this .trailing,
22
+ this .currentContextEntityType,
23
+ this .currentContextEntityId,
18
24
});
19
25
20
26
/// The headline data to display.
@@ -26,6 +32,12 @@ class HeadlineTileImageStart extends StatelessWidget {
26
32
/// An optional widget to display at the end of the tile.
27
33
final Widget ? trailing;
28
34
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
+
29
41
@override
30
42
Widget build (BuildContext context) {
31
43
final l10n = context.l10n;
@@ -50,40 +62,39 @@ class HeadlineTileImageStart extends StatelessWidget {
50
62
height: 72 ,
51
63
child: ClipRRect (
52
64
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 ,
77
76
),
78
- )
79
- : Container (
77
+ ),
78
+ );
79
+ },
80
+ errorBuilder: (context, error, stackTrace) =>
81
+ Container (
80
82
color: colorScheme.surfaceContainerHighest,
81
83
child: Icon (
82
- Icons .image_not_supported_outlined ,
84
+ Icons .broken_image_outlined ,
83
85
color: colorScheme.onSurfaceVariant,
84
86
size: AppSpacing .xl,
85
87
),
86
88
),
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
+ ),
87
98
),
88
99
),
89
100
const SizedBox (width: AppSpacing .md), // Always add spacing
@@ -105,6 +116,10 @@ class HeadlineTileImageStart extends StatelessWidget {
105
116
l10n: l10n,
106
117
colorScheme: colorScheme,
107
118
textTheme: textTheme,
119
+ currentContextEntityType:
120
+ currentContextEntityType, // Pass down
121
+ currentContextEntityId:
122
+ currentContextEntityId, // Pass down
108
123
),
109
124
],
110
125
),
@@ -128,12 +143,16 @@ class _HeadlineMetadataRow extends StatelessWidget {
128
143
required this .l10n,
129
144
required this .colorScheme,
130
145
required this .textTheme,
146
+ this .currentContextEntityType,
147
+ this .currentContextEntityId,
131
148
});
132
149
133
150
final Headline headline;
134
151
final AppLocalizations l10n;
135
152
final ColorScheme colorScheme;
136
153
final TextTheme textTheme;
154
+ final EntityType ? currentContextEntityType;
155
+ final String ? currentContextEntityId;
137
156
138
157
@override
139
158
Widget build (BuildContext context) {
@@ -177,7 +196,10 @@ class _HeadlineMetadataRow extends StatelessWidget {
177
196
],
178
197
),
179
198
),
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)) ...[
181
203
if (formattedDate.isNotEmpty)
182
204
Padding (
183
205
padding: const EdgeInsets .symmetric (
@@ -187,15 +209,12 @@ class _HeadlineMetadataRow extends StatelessWidget {
187
209
),
188
210
GestureDetector (
189
211
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),
198
216
);
217
+ }
199
218
},
200
219
child: Chip (
201
220
label: Text (headline.category! .name),
@@ -210,8 +229,14 @@ class _HeadlineMetadataRow extends StatelessWidget {
210
229
),
211
230
),
212
231
],
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)))
215
240
Padding (
216
241
padding: const EdgeInsets .symmetric (
217
242
horizontal: AppSpacing .xs / 2 ,
@@ -220,13 +245,12 @@ class _HeadlineMetadataRow extends StatelessWidget {
220
245
),
221
246
GestureDetector (
222
247
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),
229
252
);
253
+ }
230
254
},
231
255
child: Chip (
232
256
label: Text (headline.source! .name),
0 commit comments