Skip to content

Commit b13ecf9

Browse files
committed
refactor(headline_tile_image_start):
- Replace EntityType with ContentType for better clarity - Remove unused imports and reorganize remaining imports - Simplify image loading and error handling for headline image - Remove unused l10n parameter and update localization import - Update routing and entity details handling - Replace broken timeago functionality with TODO comment
1 parent c87ca08 commit b13ecf9

File tree

1 file changed

+49
-61
lines changed

1 file changed

+49
-61
lines changed

lib/shared/widgets/headline_tile_image_start.dart

Lines changed: 49 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
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
5-
import 'package:ht_main/l10n/app_localizations.dart';
2+
import 'package:go_router/go_router.dart';
3+
import 'package:ht_main/entity_details/view/entity_details_page.dart';
64
import 'package:ht_main/l10n/l10n.dart';
7-
import 'package:ht_main/router/routes.dart'; // Added
8-
import 'package:ht_shared/ht_shared.dart' show Headline;
5+
import 'package:ht_main/router/routes.dart';
6+
import 'package:ht_shared/ht_shared.dart';
97
import 'package:ht_ui_kit/ht_ui_kit.dart';
10-
// timeago import removed from here, handled by utility
118

129
/// {@template headline_tile_image_start}
1310
/// A shared widget to display a headline item with a small image at the start.
@@ -33,14 +30,13 @@ class HeadlineTileImageStart extends StatelessWidget {
3330
final Widget? trailing;
3431

3532
/// The type of the entity currently being viewed in detail (e.g., on a category page).
36-
final EntityType? currentContextEntityType;
33+
final ContentType? currentContextEntityType;
3734

3835
/// The ID of the entity currently being viewed in detail.
3936
final String? currentContextEntityId;
4037

4138
@override
4239
Widget build(BuildContext context) {
43-
final l10n = context.l10n;
4440
final theme = Theme.of(context);
4541
final textTheme = theme.textTheme;
4642
final colorScheme = theme.colorScheme;
@@ -62,39 +58,29 @@ class HeadlineTileImageStart extends StatelessWidget {
6258
height: 72,
6359
child: ClipRRect(
6460
borderRadius: BorderRadius.circular(AppSpacing.xs),
65-
child: headline.imageUrl != null
66-
? Image.network(
67-
headline.imageUrl,
68-
fit: BoxFit.cover,
69-
loadingBuilder: (context, child, loadingProgress) {
70-
if (loadingProgress == null) return child;
71-
return ColoredBox(
72-
color: colorScheme.surfaceContainerHighest,
73-
child: const Center(
74-
child: CircularProgressIndicator(
75-
strokeWidth: 2,
76-
),
77-
),
78-
);
79-
},
80-
errorBuilder: (context, error, stackTrace) =>
81-
ColoredBox(
82-
color: colorScheme.surfaceContainerHighest,
83-
child: Icon(
84-
Icons.broken_image_outlined,
85-
color: colorScheme.onSurfaceVariant,
86-
size: AppSpacing.xl,
87-
),
88-
),
89-
)
90-
: ColoredBox(
91-
color: colorScheme.surfaceContainerHighest,
92-
child: Icon(
93-
Icons.image_not_supported_outlined,
94-
color: colorScheme.onSurfaceVariant,
95-
size: AppSpacing.xl,
61+
child: Image.network(
62+
headline.imageUrl,
63+
fit: BoxFit.cover,
64+
loadingBuilder: (context, child, loadingProgress) {
65+
if (loadingProgress == null) return child;
66+
return ColoredBox(
67+
color: colorScheme.surfaceContainerHighest,
68+
child: const Center(
69+
child: CircularProgressIndicator(
70+
strokeWidth: 2,
9671
),
9772
),
73+
);
74+
},
75+
errorBuilder: (context, error, stackTrace) => ColoredBox(
76+
color: colorScheme.surfaceContainerHighest,
77+
child: Icon(
78+
Icons.broken_image_outlined,
79+
color: colorScheme.onSurfaceVariant,
80+
size: AppSpacing.xl,
81+
),
82+
),
83+
),
9884
),
9985
),
10086
const SizedBox(width: AppSpacing.md), // Always add spacing
@@ -113,7 +99,6 @@ class HeadlineTileImageStart extends StatelessWidget {
11399
const SizedBox(height: AppSpacing.sm),
114100
_HeadlineMetadataRow(
115101
headline: headline,
116-
l10n: l10n,
117102
colorScheme: colorScheme,
118103
textTheme: textTheme,
119104
currentContextEntityType:
@@ -140,23 +125,22 @@ class HeadlineTileImageStart extends StatelessWidget {
140125
class _HeadlineMetadataRow extends StatelessWidget {
141126
const _HeadlineMetadataRow({
142127
required this.headline,
143-
required this.l10n,
144128
required this.colorScheme,
145129
required this.textTheme,
146130
this.currentContextEntityType,
147131
this.currentContextEntityId,
148132
});
149133

150134
final Headline headline;
151-
final AppLocalizations l10n;
152135
final ColorScheme colorScheme;
153136
final TextTheme textTheme;
154-
final EntityType? currentContextEntityType;
137+
final ContentType? currentContextEntityType;
155138
final String? currentContextEntityId;
156139

157140
@override
158141
Widget build(BuildContext context) {
159-
final formattedDate = formatRelativeTime(context, headline.publishedAt);
142+
// TODO(anyone): Use a proper timeago library.
143+
final formattedDate = headline.createdAt.toString();
160144

161145
// Use bodySmall for a reasonable base size, with muted accent color
162146
final metadataTextStyle = textTheme.bodySmall?.copyWith(
@@ -184,34 +168,35 @@ class _HeadlineMetadataRow extends StatelessWidget {
184168
Text(formattedDate, style: metadataTextStyle),
185169
],
186170
),
187-
// Conditionally render Category as Text
188-
if (headline.category?.name != null &&
189-
!(currentContextEntityType == EntityType.category &&
190-
headline.category!.id == currentContextEntityId)) ...[
171+
// Conditionally render Topic as Text
172+
if (headline.topic.name.isNotEmpty &&
173+
!(currentContextEntityType == ContentType.topic &&
174+
headline.topic.id == currentContextEntityId)) ...[
191175
if (formattedDate.isNotEmpty)
192176
Padding(
193177
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xs),
194178
child: Text('•', style: metadataTextStyle),
195179
),
196180
GestureDetector(
197181
onTap: () {
198-
if (headline.category != null) {
199-
context.push(
200-
Routes.categoryDetails,
201-
extra: EntityDetailsPageArguments(entity: headline.category),
202-
);
203-
}
182+
context.push(
183+
Routes.topicDetails,
184+
extra: EntityDetailsPageArguments(
185+
entity: headline.topic,
186+
entityType: ContentType.topic,
187+
),
188+
);
204189
},
205-
child: Text(headline.category!.name, style: metadataTextStyle),
190+
child: Text(headline.topic.name, style: metadataTextStyle),
206191
),
207192
],
208193
// Conditionally render Source as Text
209-
if (!(currentContextEntityType == EntityType.source &&
194+
if (!(currentContextEntityType == ContentType.source &&
210195
headline.source.id == currentContextEntityId)) ...[
211196
if (formattedDate.isNotEmpty ||
212-
(headline.category?.name != null &&
213-
!(currentContextEntityType == EntityType.category &&
214-
headline.category!.id == currentContextEntityId)))
197+
(headline.topic.name.isNotEmpty &&
198+
!(currentContextEntityType == ContentType.topic &&
199+
headline.topic.id == currentContextEntityId)))
215200
Padding(
216201
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xs),
217202
child: Text('•', style: metadataTextStyle),
@@ -220,7 +205,10 @@ class _HeadlineMetadataRow extends StatelessWidget {
220205
onTap: () {
221206
context.push(
222207
Routes.sourceDetails,
223-
extra: EntityDetailsPageArguments(entity: headline.source),
208+
extra: EntityDetailsPageArguments(
209+
entity: headline.source,
210+
entityType: ContentType.source,
211+
),
224212
);
225213
},
226214
child: Text(headline.source.name, style: metadataTextStyle),

0 commit comments

Comments
 (0)