Skip to content

Commit a53ed40

Browse files
committed
don't load failed image urls again in a session
1 parent 3cf1a79 commit a53ed40

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

lib/common/view/safe_network_image.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class SafeNetworkImage extends StatelessWidget {
3737
final Map<String, String>? httpHeaders;
3838
final Function(ImageProvider imageProvider)? onImageLoaded;
3939

40+
static final List<String> _failedUrls = [];
41+
4042
@override
4143
Widget build(BuildContext context) {
4244
final fallBack = Center(
@@ -45,7 +47,11 @@ class SafeNetworkImage extends StatelessWidget {
4547
Icon(Iconz.musicNote, size: height != null ? height! * 0.7 : null),
4648
);
4749

48-
if (url == null) return fallBack;
50+
if (url == null ||
51+
url!.isEmpty ||
52+
_failedUrls.contains(url!) ||
53+
(Uri.tryParse(url!)?.host.isEmpty ?? false))
54+
return fallBack;
4955

5056
final errorWidget = Center(
5157
child:
@@ -72,9 +78,18 @@ class SafeNetworkImage extends StatelessWidget {
7278
);
7379
},
7480
errorWidget: (context, url, _) => errorWidget,
75-
errorListener: (e) => printMessageInDebugMode(e.toString()),
81+
errorListener: (e) {
82+
printMessageInDebugMode('Failed to load image: $url');
83+
if (url != null) {
84+
_failedUrls.add(url!);
85+
}
86+
},
7687
);
7788
} on Exception {
89+
printMessageInDebugMode('Failed to load image: $url');
90+
if (url != null) {
91+
_failedUrls.add(url!);
92+
}
7893
return fallBack;
7994
}
8095
}

lib/common/view/sliver_audio_tile_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SliverAudioTileList extends StatelessWidget with WatchItMixin {
5656
showSlimTileSubtitle: width >= 900,
5757
showSecondLineSubTitle: width < 900,
5858
allowLeadingImage: allowLeadingImage,
59-
key: ValueKey(audio.path ?? audio.url),
59+
key: ValueKey(audio.path ?? audio.url ?? index),
6060
audioPageType: audioPageType,
6161
onSubTitleTap: onSubTitleTab,
6262
isPlayerPlaying: isPlaying,

lib/search/search_model.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,15 @@ class SearchModel extends SafeChangeNotifier {
270270
(v) => setRadioSearchResult(
271271
_searchQuery == null || _searchQuery!.isEmpty
272272
? null
273-
: v?.map((e) => Audio.fromStation(e)).toList(),
273+
: v?.map(Audio.fromStation).toList(),
274274
),
275275
)
276276
.then((_) => _loading = false),
277277
SearchType.radioTag =>
278278
await _radioService
279279
.search(tag: _tag?.name, limit: _radioLimit)
280280
.then(
281-
(v) => setRadioSearchResult(
282-
v?.map((e) => Audio.fromStation(e)).toList(),
283-
),
281+
(v) => setRadioSearchResult(v?.map(Audio.fromStation).toList()),
284282
)
285283
.then((_) => _loading = false),
286284
SearchType.radioCountry =>
@@ -296,9 +294,7 @@ class SearchModel extends SafeChangeNotifier {
296294
await _radioService
297295
.search(language: _language?.name.toLowerCase(), limit: _radioLimit)
298296
.then(
299-
(v) => setRadioSearchResult(
300-
v?.map((e) => Audio.fromStation(e)).toList(),
301-
),
297+
(v) => setRadioSearchResult(v?.map(Audio.fromStation).toList()),
302298
)
303299
.then((_) => _loading = false),
304300
SearchType.podcastTitle =>

0 commit comments

Comments
 (0)