Skip to content

Commit 25ae204

Browse files
committed
fix(entity_details): improve entity icon URL logic and error handling
- Use switch statement for entityIconUrl assignment, adding Source support - Display fallback icon for Source entities and on image error - Remove duplicate code for Source entity icon handling
1 parent 0bcc9ae commit 25ae204

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

lib/entity_details/view/entity_details_page.dart

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,12 @@ class _EntityDetailsViewState extends State<EntityDetailsView> {
208208
},
209209
);
210210

211-
final entityIconUrl = (state.entity is Topic)
212-
? (state.entity! as Topic).iconUrl
213-
: (state.entity is Country)
214-
? (state.entity! as Country).flagUrl
215-
: null;
211+
final entityIconUrl = switch (state.entity) {
212+
final Topic topic => topic.iconUrl,
213+
final Country country => country.flagUrl,
214+
final Source source => source.logoUrl,
215+
_ => null,
216+
};
216217

217218
final Widget appBarTitleWidget = Row(
218219
mainAxisSize: MainAxisSize.min,
@@ -229,21 +230,13 @@ class _EntityDetailsViewState extends State<EntityDetailsView> {
229230
width: AppSpacing.xxl,
230231
height: AppSpacing.xxl,
231232
fit: BoxFit.contain,
232-
errorBuilder: (context, error, stackTrace) =>
233-
const SizedBox(),
233+
errorBuilder: (context, error, stackTrace) => Icon(
234+
appBarIconData,
235+
size: AppSpacing.xxl,
236+
color: colorScheme.onSurface,
237+
),
234238
),
235239
),
236-
)
237-
else if (state.entity is Source && appBarIconData != null)
238-
Padding(
239-
padding: Directionality.of(context) == TextDirection.ltr
240-
? const EdgeInsets.only(right: AppSpacing.md)
241-
: const EdgeInsets.only(left: AppSpacing.md),
242-
child: Icon(
243-
appBarIconData,
244-
size: AppSpacing.xxl,
245-
color: colorScheme.onSurface,
246-
),
247240
),
248241
Expanded(
249242
child: Text(

0 commit comments

Comments
 (0)