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;
@@ -17,6 +21,8 @@ class HeadlineTileTextOnly extends StatelessWidget {
17
21
super .key,
18
22
this .onHeadlineTap,
19
23
this .trailing,
24
+ this .currentContextEntityType,
25
+ this .currentContextEntityId,
20
26
});
21
27
22
28
/// The headline data to display.
@@ -28,6 +34,12 @@ class HeadlineTileTextOnly extends StatelessWidget {
28
34
/// An optional widget to display at the end of the tile.
29
35
final Widget ? trailing;
30
36
37
+ /// The type of the entity currently being viewed in detail (e.g., on a category page).
38
+ final EntityType ? currentContextEntityType;
39
+
40
+ /// The ID of the entity currently being viewed in detail.
41
+ final String ? currentContextEntityId;
42
+
31
43
@override
32
44
Widget build (BuildContext context) {
33
45
final l10n = context.l10n;
@@ -65,6 +77,10 @@ class HeadlineTileTextOnly extends StatelessWidget {
65
77
l10n: l10n,
66
78
colorScheme: colorScheme,
67
79
textTheme: textTheme,
80
+ currentContextEntityType:
81
+ currentContextEntityType, // Pass down
82
+ currentContextEntityId:
83
+ currentContextEntityId, // Pass down
68
84
),
69
85
],
70
86
),
@@ -88,12 +104,16 @@ class _HeadlineMetadataRow extends StatelessWidget {
88
104
required this .l10n,
89
105
required this .colorScheme,
90
106
required this .textTheme,
107
+ this .currentContextEntityType,
108
+ this .currentContextEntityId,
91
109
});
92
110
93
111
final Headline headline;
94
112
final AppLocalizations l10n;
95
113
final ColorScheme colorScheme;
96
114
final TextTheme textTheme;
115
+ final EntityType ? currentContextEntityType;
116
+ final String ? currentContextEntityId;
97
117
98
118
@override
99
119
Widget build (BuildContext context) {
@@ -137,7 +157,10 @@ class _HeadlineMetadataRow extends StatelessWidget {
137
157
],
138
158
),
139
159
),
140
- if (headline.category? .name != null ) ...[
160
+ // Conditionally render Category Chip
161
+ if (headline.category? .name != null &&
162
+ ! (currentContextEntityType == EntityType .category &&
163
+ headline.category! .id == currentContextEntityId)) ...[
141
164
if (formattedDate.isNotEmpty)
142
165
Padding (
143
166
padding: const EdgeInsets .symmetric (
@@ -147,15 +170,12 @@ class _HeadlineMetadataRow extends StatelessWidget {
147
170
),
148
171
GestureDetector (
149
172
onTap: () {
150
- ScaffoldMessenger .of (context)
151
- ..hideCurrentSnackBar ()
152
- ..showSnackBar (
153
- SnackBar (
154
- content: Text (
155
- 'Tapped Category: ${headline .category !.name }' ,
156
- ),
157
- ),
173
+ if (headline.category != null ) {
174
+ context.push (
175
+ Routes .categoryDetails,
176
+ extra: EntityDetailsPageArguments (entity: headline.category),
158
177
);
178
+ }
159
179
},
160
180
child: Chip (
161
181
label: Text (headline.category! .name),
@@ -170,8 +190,14 @@ class _HeadlineMetadataRow extends StatelessWidget {
170
190
),
171
191
),
172
192
],
173
- if (headline.source? .name != null ) ...[
174
- if (formattedDate.isNotEmpty || headline.category? .name != null )
193
+ // Conditionally render Source Chip
194
+ if (headline.source? .name != null &&
195
+ ! (currentContextEntityType == EntityType .source &&
196
+ headline.source! .id == currentContextEntityId)) ...[
197
+ if (formattedDate.isNotEmpty ||
198
+ (headline.category? .name != null &&
199
+ ! (currentContextEntityType == EntityType .category &&
200
+ headline.category! .id == currentContextEntityId)))
175
201
Padding (
176
202
padding: const EdgeInsets .symmetric (
177
203
horizontal: AppSpacing .xs / 2 ,
@@ -180,13 +206,12 @@ class _HeadlineMetadataRow extends StatelessWidget {
180
206
),
181
207
GestureDetector (
182
208
onTap: () {
183
- ScaffoldMessenger .of (context)
184
- ..hideCurrentSnackBar ()
185
- ..showSnackBar (
186
- SnackBar (
187
- content: Text ('Tapped Source: ${headline .source !.name }' ),
188
- ),
209
+ if (headline.source != null ) {
210
+ context.push (
211
+ Routes .sourceDetails,
212
+ extra: EntityDetailsPageArguments (entity: headline.source),
189
213
);
214
+ }
190
215
},
191
216
child: Chip (
192
217
label: Text (headline.source! .name),
0 commit comments