Skip to content

Commit 0147a64

Browse files
committed
feat: Navigate to category/source details
- Added category/source navigation - Passed context entity info - Conditional chip rendering
1 parent 07b7101 commit 0147a64

File tree

1 file changed

+42
-17
lines changed

1 file changed

+42
-17
lines changed

lib/shared/widgets/headline_tile_text_only.dart

Lines changed: 42 additions & 17 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;
@@ -17,6 +21,8 @@ class HeadlineTileTextOnly extends StatelessWidget {
1721
super.key,
1822
this.onHeadlineTap,
1923
this.trailing,
24+
this.currentContextEntityType,
25+
this.currentContextEntityId,
2026
});
2127

2228
/// The headline data to display.
@@ -28,6 +34,12 @@ class HeadlineTileTextOnly extends StatelessWidget {
2834
/// An optional widget to display at the end of the tile.
2935
final Widget? trailing;
3036

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+
3143
@override
3244
Widget build(BuildContext context) {
3345
final l10n = context.l10n;
@@ -65,6 +77,10 @@ class HeadlineTileTextOnly extends StatelessWidget {
6577
l10n: l10n,
6678
colorScheme: colorScheme,
6779
textTheme: textTheme,
80+
currentContextEntityType:
81+
currentContextEntityType, // Pass down
82+
currentContextEntityId:
83+
currentContextEntityId, // Pass down
6884
),
6985
],
7086
),
@@ -88,12 +104,16 @@ class _HeadlineMetadataRow extends StatelessWidget {
88104
required this.l10n,
89105
required this.colorScheme,
90106
required this.textTheme,
107+
this.currentContextEntityType,
108+
this.currentContextEntityId,
91109
});
92110

93111
final Headline headline;
94112
final AppLocalizations l10n;
95113
final ColorScheme colorScheme;
96114
final TextTheme textTheme;
115+
final EntityType? currentContextEntityType;
116+
final String? currentContextEntityId;
97117

98118
@override
99119
Widget build(BuildContext context) {
@@ -137,7 +157,10 @@ class _HeadlineMetadataRow extends StatelessWidget {
137157
],
138158
),
139159
),
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)) ...[
141164
if (formattedDate.isNotEmpty)
142165
Padding(
143166
padding: const EdgeInsets.symmetric(
@@ -147,15 +170,12 @@ class _HeadlineMetadataRow extends StatelessWidget {
147170
),
148171
GestureDetector(
149172
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),
158177
);
178+
}
159179
},
160180
child: Chip(
161181
label: Text(headline.category!.name),
@@ -170,8 +190,14 @@ class _HeadlineMetadataRow extends StatelessWidget {
170190
),
171191
),
172192
],
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)))
175201
Padding(
176202
padding: const EdgeInsets.symmetric(
177203
horizontal: AppSpacing.xs / 2,
@@ -180,13 +206,12 @@ class _HeadlineMetadataRow extends StatelessWidget {
180206
),
181207
GestureDetector(
182208
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),
189213
);
214+
}
190215
},
191216
child: Chip(
192217
label: Text(headline.source!.name),

0 commit comments

Comments
 (0)