Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix stale cover caching in detail sheet and home widget

Barnabas011ba79d34bb
diff --git a/lib/services/home_widget_service.dart b/lib/services/home_widget_service.dart
index 766935dc..cfd3b7eb 100644
--- a/lib/services/home_widget_service.dart
+++ b/lib/services/home_widget_service.dart
@@ -247,8 +247,11 @@ class HomeWidgetService {
}
Future<void> _updateCoverArt(String itemId) async {
- if (_lastCoverItemId == itemId) return;
- _lastCoverItemId = itemId;
+ final player = AudioPlayerService();
+ final coverUrl = player.currentCoverUrl;
+ final cacheKey = '$itemId|$coverUrl';
+ if (_lastCoverItemId == cacheKey) return;
+ _lastCoverItemId = cacheKey;
String? coverPath;
@@ -261,8 +264,6 @@ class HomeWidgetService {
// If no local cover, download from server to a temp file.
if (coverPath == null) {
- final player = AudioPlayerService();
- final coverUrl = player.currentCoverUrl;
if (coverUrl != null && coverUrl.isNotEmpty) {
final cacheDir = await getTemporaryDirectory();
final widgetCoverDir = Directory('${cacheDir.path}/widget_covers');
diff --git a/lib/widgets/book_detail_sheet.dart b/lib/widgets/book_detail_sheet.dart
index f6adc2d9..b369e1f0 100644
--- a/lib/widgets/book_detail_sheet.dart
+++ b/lib/widgets/book_detail_sheet.dart
@@ -219,16 +219,14 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {
String? get _coverUrl {
final localCover = _item?['_localCoverUrl'] as String?;
if (localCover != null && localCover.isNotEmpty) return localCover;
- final auth = context.read<AuthProvider>();
- return auth.apiService?.getCoverUrl(widget.itemId, width: 800);
+ return context.read<LibraryProvider>().getCoverUrl(widget.itemId, width: 800);
}
/// Full-res cover for the viewer and sharing.
String? get _fullResCoverUrl {
final localCover = _item?['_localCoverUrl'] as String?;
if (localCover != null && localCover.isNotEmpty) return localCover;
- final auth = context.read<AuthProvider>();
- return auth.apiService?.getCoverUrl(widget.itemId, width: 4000);
+ return context.read<LibraryProvider>().getCoverUrl(widget.itemId, width: 4000);
}