|
1 | 1 | import 'package:flutter/material.dart';
|
2 | 2 | import 'package:ht_main/l10n/l10n.dart';
|
3 | 3 | import 'package:ht_main/shared/constants/app_spacing.dart';
|
| 4 | +import 'package:ht_main/shared/utils/utils.dart'; // Import the new utility |
4 | 5 | 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 |
6 | 7 |
|
7 | 8 | /// {@template headline_tile_image_top}
|
8 | 9 | /// A shared widget to display a headline item with a large image at the top.
|
@@ -146,109 +147,100 @@ class _HeadlineMetadataRow extends StatelessWidget {
|
146 | 147 |
|
147 | 148 | @override
|
148 | 149 | 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); |
158 | 151 |
|
159 | 152 | final metadataStyle = textTheme.bodySmall?.copyWith(
|
160 | 153 | color: colorScheme.onSurfaceVariant,
|
161 | 154 | );
|
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 |
163 | 161 |
|
164 | 162 | return Wrap(
|
165 |
| - spacing: AppSpacing.md, |
| 163 | + spacing: AppSpacing.sm, // Reduced spacing for more compactness |
166 | 164 | runSpacing: AppSpacing.xs,
|
167 | 165 | crossAxisAlignment: WrapCrossAlignment.center,
|
168 | 166 | children: [
|
169 |
| - if (headline.category?.name != null) |
| 167 | + if (formattedDate.isNotEmpty) |
170 | 168 | GestureDetector(
|
171 | 169 | onTap: () {
|
172 | 170 | ScaffoldMessenger.of(context)
|
173 | 171 | ..hideCurrentSnackBar()
|
174 | 172 | ..showSnackBar(
|
175 |
| - SnackBar( |
176 |
| - content: Text( |
177 |
| - 'Tapped Category: ${headline.category!.name}', |
178 |
| - ), |
179 |
| - ), |
| 173 | + SnackBar(content: Text('Tapped Date: $formattedDate')), |
180 | 174 | );
|
181 | 175 | },
|
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 | + ], |
196 | 187 | ),
|
197 | 188 | ),
|
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 | + ), |
199 | 196 | GestureDetector(
|
200 | 197 | onTap: () {
|
201 | 198 | ScaffoldMessenger.of(context)
|
202 | 199 | ..hideCurrentSnackBar()
|
203 | 200 | ..showSnackBar(
|
204 | 201 | SnackBar(
|
205 |
| - content: Text('Tapped Source: ${headline.source!.name}'), |
| 202 | + content: |
| 203 | + Text('Tapped Category: ${headline.category!.name}'), |
206 | 204 | ),
|
207 | 205 | );
|
208 | 206 | },
|
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, |
226 | 214 | ),
|
227 | 215 | ),
|
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 | + ), |
229 | 224 | GestureDetector(
|
230 | 225 | onTap: () {
|
231 | 226 | ScaffoldMessenger.of(context)
|
232 | 227 | ..hideCurrentSnackBar()
|
233 | 228 | ..showSnackBar(
|
234 | 229 | SnackBar(
|
235 |
| - content: Text('Tapped Date: $formattedDate'), |
| 230 | + content: Text('Tapped Source: ${headline.source!.name}'), |
236 | 231 | ),
|
237 | 232 | );
|
238 | 233 | },
|
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, |
250 | 241 | ),
|
251 | 242 | ),
|
| 243 | + ], |
252 | 244 | ],
|
253 | 245 | );
|
254 | 246 | }
|
|
0 commit comments