Skip to content

Commit c9e6b4d

Browse files
committed
refactor(tile): improve metadata display
- Replaced timeago with custom utility - Used chips for categories/sources - Compacted metadata row
1 parent 9186160 commit c9e6b4d

File tree

1 file changed

+56
-64
lines changed

1 file changed

+56
-64
lines changed

lib/shared/widgets/headline_tile_image_start.dart

Lines changed: 56 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:ht_main/l10n/l10n.dart';
33
import 'package:ht_main/shared/constants/app_spacing.dart';
4+
import 'package:ht_main/shared/utils/utils.dart'; // Import the new utility
45
import 'package:ht_shared/ht_shared.dart' show Headline;
5-
import 'package:timeago/timeago.dart' as timeago;
6+
// timeago import removed from here, handled by utility
67

78
/// {@template headline_tile_image_start}
89
/// A shared widget to display a headline item with a small image at the start.
@@ -134,109 +135,100 @@ class _HeadlineMetadataRow extends StatelessWidget {
134135

135136
@override
136137
Widget build(BuildContext context) {
137-
final String formattedDate;
138-
if (headline.publishedAt != null) {
139-
formattedDate = timeago.format(
140-
headline.publishedAt!,
141-
locale: Localizations.localeOf(context).languageCode,
142-
);
143-
} else {
144-
formattedDate = '';
145-
}
138+
final formattedDate = formatRelativeTime(context, headline.publishedAt);
146139

147140
final metadataStyle = textTheme.bodySmall?.copyWith(
148141
color: colorScheme.onSurfaceVariant,
149142
);
150-
const iconSize = 12.0;
143+
final chipLabelStyle = textTheme.labelSmall?.copyWith(
144+
color: colorScheme.onSurfaceVariant,
145+
);
146+
final chipBackgroundColor =
147+
colorScheme.surfaceContainerHighest.withOpacity(0.5);
148+
const iconSize = 12.0; // Kept for date icon
151149

152150
return Wrap(
153-
spacing: AppSpacing.md,
151+
spacing: AppSpacing.sm, // Reduced spacing for more compactness
154152
runSpacing: AppSpacing.xs,
155153
crossAxisAlignment: WrapCrossAlignment.center,
156154
children: [
157-
if (headline.category?.name != null)
155+
if (formattedDate.isNotEmpty)
158156
GestureDetector(
159157
onTap: () {
160158
ScaffoldMessenger.of(context)
161159
..hideCurrentSnackBar()
162160
..showSnackBar(
163-
SnackBar(
164-
content: Text(
165-
'Tapped Category: ${headline.category!.name}',
166-
),
167-
),
161+
SnackBar(content: Text('Tapped Date: $formattedDate')),
168162
);
169163
},
170-
child: Chip(
171-
avatar: Icon(
172-
Icons.label_outline,
173-
size: iconSize,
174-
color: colorScheme.onSurfaceVariant, // Changed color
175-
),
176-
label: Text(headline.category!.name),
177-
labelStyle: textTheme.labelSmall?.copyWith(
178-
color: colorScheme.onSurfaceVariant, // Changed color
179-
),
180-
// backgroundColor removed
181-
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.sm),
182-
visualDensity: VisualDensity.compact,
183-
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
164+
child: Row(
165+
mainAxisSize: MainAxisSize.min,
166+
children: [
167+
Icon(
168+
Icons.calendar_today_outlined,
169+
size: iconSize,
170+
color: colorScheme.onSurfaceVariant,
171+
),
172+
const SizedBox(width: AppSpacing.xs),
173+
Text(formattedDate, style: metadataStyle),
174+
],
184175
),
185176
),
186-
if (headline.source?.name != null)
177+
if (headline.category?.name != null) ...[
178+
if (formattedDate.isNotEmpty)
179+
Padding(
180+
padding:
181+
const EdgeInsets.symmetric(horizontal: AppSpacing.xs / 2),
182+
child: Text('•', style: metadataStyle),
183+
),
187184
GestureDetector(
188185
onTap: () {
189186
ScaffoldMessenger.of(context)
190187
..hideCurrentSnackBar()
191188
..showSnackBar(
192189
SnackBar(
193-
content: Text('Tapped Source: ${headline.source!.name}'),
190+
content:
191+
Text('Tapped Category: ${headline.category!.name}'),
194192
),
195193
);
196194
},
197-
child: Row(
198-
mainAxisSize: MainAxisSize.min,
199-
children: [
200-
Icon(
201-
Icons.source_outlined,
202-
size: iconSize,
203-
color: colorScheme.onSurfaceVariant,
204-
),
205-
const SizedBox(width: AppSpacing.xs),
206-
Flexible(
207-
child: Text(
208-
headline.source!.name,
209-
style: metadataStyle,
210-
overflow: TextOverflow.ellipsis,
211-
),
212-
),
213-
],
195+
child: Chip(
196+
label: Text(headline.category!.name),
197+
labelStyle: chipLabelStyle,
198+
backgroundColor: chipBackgroundColor,
199+
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.sm),
200+
visualDensity: VisualDensity.compact,
201+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
214202
),
215203
),
216-
if (formattedDate.isNotEmpty)
204+
],
205+
if (headline.source?.name != null) ...[
206+
if (formattedDate.isNotEmpty || headline.category?.name != null)
207+
Padding(
208+
padding:
209+
const EdgeInsets.symmetric(horizontal: AppSpacing.xs / 2),
210+
child: Text('•', style: metadataStyle),
211+
),
217212
GestureDetector(
218213
onTap: () {
219214
ScaffoldMessenger.of(context)
220215
..hideCurrentSnackBar()
221216
..showSnackBar(
222217
SnackBar(
223-
content: Text('Tapped Date: $formattedDate'),
218+
content: Text('Tapped Source: ${headline.source!.name}'),
224219
),
225220
);
226221
},
227-
child: Row(
228-
mainAxisSize: MainAxisSize.min,
229-
children: [
230-
Icon(
231-
Icons.calendar_today_outlined,
232-
size: iconSize,
233-
color: colorScheme.onSurfaceVariant,
234-
),
235-
const SizedBox(width: AppSpacing.xs),
236-
Text(formattedDate, style: metadataStyle),
237-
],
222+
child: Chip(
223+
label: Text(headline.source!.name),
224+
labelStyle: chipLabelStyle,
225+
backgroundColor: chipBackgroundColor,
226+
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.sm),
227+
visualDensity: VisualDensity.compact,
228+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
238229
),
239230
),
231+
],
240232
],
241233
);
242234
}

0 commit comments

Comments
 (0)