|
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_start}
|
8 | 9 | /// A shared widget to display a headline item with a small image at the start.
|
@@ -134,109 +135,100 @@ class _HeadlineMetadataRow extends StatelessWidget {
|
134 | 135 |
|
135 | 136 | @override
|
136 | 137 | 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); |
146 | 139 |
|
147 | 140 | final metadataStyle = textTheme.bodySmall?.copyWith(
|
148 | 141 | color: colorScheme.onSurfaceVariant,
|
149 | 142 | );
|
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 |
151 | 149 |
|
152 | 150 | return Wrap(
|
153 |
| - spacing: AppSpacing.md, |
| 151 | + spacing: AppSpacing.sm, // Reduced spacing for more compactness |
154 | 152 | runSpacing: AppSpacing.xs,
|
155 | 153 | crossAxisAlignment: WrapCrossAlignment.center,
|
156 | 154 | children: [
|
157 |
| - if (headline.category?.name != null) |
| 155 | + if (formattedDate.isNotEmpty) |
158 | 156 | GestureDetector(
|
159 | 157 | onTap: () {
|
160 | 158 | ScaffoldMessenger.of(context)
|
161 | 159 | ..hideCurrentSnackBar()
|
162 | 160 | ..showSnackBar(
|
163 |
| - SnackBar( |
164 |
| - content: Text( |
165 |
| - 'Tapped Category: ${headline.category!.name}', |
166 |
| - ), |
167 |
| - ), |
| 161 | + SnackBar(content: Text('Tapped Date: $formattedDate')), |
168 | 162 | );
|
169 | 163 | },
|
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 | + ], |
184 | 175 | ),
|
185 | 176 | ),
|
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 | + ), |
187 | 184 | GestureDetector(
|
188 | 185 | onTap: () {
|
189 | 186 | ScaffoldMessenger.of(context)
|
190 | 187 | ..hideCurrentSnackBar()
|
191 | 188 | ..showSnackBar(
|
192 | 189 | SnackBar(
|
193 |
| - content: Text('Tapped Source: ${headline.source!.name}'), |
| 190 | + content: |
| 191 | + Text('Tapped Category: ${headline.category!.name}'), |
194 | 192 | ),
|
195 | 193 | );
|
196 | 194 | },
|
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, |
214 | 202 | ),
|
215 | 203 | ),
|
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 | + ), |
217 | 212 | GestureDetector(
|
218 | 213 | onTap: () {
|
219 | 214 | ScaffoldMessenger.of(context)
|
220 | 215 | ..hideCurrentSnackBar()
|
221 | 216 | ..showSnackBar(
|
222 | 217 | SnackBar(
|
223 |
| - content: Text('Tapped Date: $formattedDate'), |
| 218 | + content: Text('Tapped Source: ${headline.source!.name}'), |
224 | 219 | ),
|
225 | 220 | );
|
226 | 221 | },
|
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, |
238 | 229 | ),
|
239 | 230 | ),
|
| 231 | + ], |
240 | 232 | ],
|
241 | 233 | );
|
242 | 234 | }
|
|
0 commit comments