Skip to content

Commit c8e707a

Browse files
committed
refactor(tile): improve headline metadata display
- Use chip for category/source - Use util for relative time - Improve visual density
1 parent c9e6b4d commit c8e707a

File tree

1 file changed

+56
-64
lines changed

1 file changed

+56
-64
lines changed

lib/shared/widgets/headline_tile_image_top.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_top}
89
/// A shared widget to display a headline item with a large image at the top.
@@ -146,109 +147,100 @@ class _HeadlineMetadataRow extends StatelessWidget {
146147

147148
@override
148149
Widget build(BuildContext context) {
149-
final String formattedDate;
150-
if (headline.publishedAt != null) {
151-
formattedDate = timeago.format(
152-
headline.publishedAt!,
153-
locale: Localizations.localeOf(context).languageCode,
154-
);
155-
} else {
156-
formattedDate = '';
157-
}
150+
final formattedDate = formatRelativeTime(context, headline.publishedAt);
158151

159152
final metadataStyle = textTheme.bodySmall?.copyWith(
160153
color: colorScheme.onSurfaceVariant,
161154
);
162-
const iconSize = 12.0;
155+
final chipLabelStyle = textTheme.labelSmall?.copyWith(
156+
color: colorScheme.onSurfaceVariant,
157+
);
158+
final chipBackgroundColor =
159+
colorScheme.surfaceContainerHighest.withOpacity(0.5);
160+
const iconSize = 12.0; // Kept for date icon
163161

164162
return Wrap(
165-
spacing: AppSpacing.md,
163+
spacing: AppSpacing.sm, // Reduced spacing for more compactness
166164
runSpacing: AppSpacing.xs,
167165
crossAxisAlignment: WrapCrossAlignment.center,
168166
children: [
169-
if (headline.category?.name != null)
167+
if (formattedDate.isNotEmpty)
170168
GestureDetector(
171169
onTap: () {
172170
ScaffoldMessenger.of(context)
173171
..hideCurrentSnackBar()
174172
..showSnackBar(
175-
SnackBar(
176-
content: Text(
177-
'Tapped Category: ${headline.category!.name}',
178-
),
179-
),
173+
SnackBar(content: Text('Tapped Date: $formattedDate')),
180174
);
181175
},
182-
child: Chip(
183-
avatar: Icon(
184-
Icons.label_outline,
185-
size: iconSize,
186-
color: colorScheme.onSurfaceVariant, // Changed color
187-
),
188-
label: Text(headline.category!.name),
189-
labelStyle: textTheme.labelSmall?.copyWith(
190-
color: colorScheme.onSurfaceVariant, // Changed color
191-
),
192-
// backgroundColor removed
193-
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.sm),
194-
visualDensity: VisualDensity.compact,
195-
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
176+
child: Row(
177+
mainAxisSize: MainAxisSize.min,
178+
children: [
179+
Icon(
180+
Icons.calendar_today_outlined,
181+
size: iconSize,
182+
color: colorScheme.onSurfaceVariant,
183+
),
184+
const SizedBox(width: AppSpacing.xs),
185+
Text(formattedDate, style: metadataStyle),
186+
],
196187
),
197188
),
198-
if (headline.source?.name != null)
189+
if (headline.category?.name != null) ...[
190+
if (formattedDate.isNotEmpty)
191+
Padding(
192+
padding:
193+
const EdgeInsets.symmetric(horizontal: AppSpacing.xs / 2),
194+
child: Text('•', style: metadataStyle),
195+
),
199196
GestureDetector(
200197
onTap: () {
201198
ScaffoldMessenger.of(context)
202199
..hideCurrentSnackBar()
203200
..showSnackBar(
204201
SnackBar(
205-
content: Text('Tapped Source: ${headline.source!.name}'),
202+
content:
203+
Text('Tapped Category: ${headline.category!.name}'),
206204
),
207205
);
208206
},
209-
child: Row(
210-
mainAxisSize: MainAxisSize.min,
211-
children: [
212-
Icon(
213-
Icons.source_outlined,
214-
size: iconSize,
215-
color: colorScheme.onSurfaceVariant,
216-
),
217-
const SizedBox(width: AppSpacing.xs),
218-
Flexible(
219-
child: Text(
220-
headline.source!.name,
221-
style: metadataStyle,
222-
overflow: TextOverflow.ellipsis,
223-
),
224-
),
225-
],
207+
child: Chip(
208+
label: Text(headline.category!.name),
209+
labelStyle: chipLabelStyle,
210+
backgroundColor: chipBackgroundColor,
211+
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.sm),
212+
visualDensity: VisualDensity.compact,
213+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
226214
),
227215
),
228-
if (formattedDate.isNotEmpty)
216+
],
217+
if (headline.source?.name != null) ...[
218+
if (formattedDate.isNotEmpty || headline.category?.name != null)
219+
Padding(
220+
padding:
221+
const EdgeInsets.symmetric(horizontal: AppSpacing.xs / 2),
222+
child: Text('•', style: metadataStyle),
223+
),
229224
GestureDetector(
230225
onTap: () {
231226
ScaffoldMessenger.of(context)
232227
..hideCurrentSnackBar()
233228
..showSnackBar(
234229
SnackBar(
235-
content: Text('Tapped Date: $formattedDate'),
230+
content: Text('Tapped Source: ${headline.source!.name}'),
236231
),
237232
);
238233
},
239-
child: Row(
240-
mainAxisSize: MainAxisSize.min,
241-
children: [
242-
Icon(
243-
Icons.calendar_today_outlined,
244-
size: iconSize,
245-
color: colorScheme.onSurfaceVariant,
246-
),
247-
const SizedBox(width: AppSpacing.xs),
248-
Text(formattedDate, style: metadataStyle),
249-
],
234+
child: Chip(
235+
label: Text(headline.source!.name),
236+
labelStyle: chipLabelStyle,
237+
backgroundColor: chipBackgroundColor,
238+
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.sm),
239+
visualDensity: VisualDensity.compact,
240+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
250241
),
251242
),
243+
],
252244
],
253245
);
254246
}

0 commit comments

Comments
 (0)