From 773cf12b97ceb1e00c0591e059c982cfeb6e8612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Tue, 28 May 2024 18:54:05 +0200 Subject: [PATCH] fix: actual caching fixes #1 --- lib/api/audio/audioplayer_service.dart | 1 + lib/api/subsonic/artist.dart | 2 +- lib/views/album_view.dart | 1 + lib/views/artist_view.dart | 4 +++- lib/views/home_view.dart | 3 ++- lib/widgets/hero_banner.dart | 3 +++ lib/widgets/image_cover.dart | 3 +++ lib/widgets/player.dart | 14 ++------------ lib/widgets/song_row.dart | 13 +++++++++++-- 9 files changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/api/audio/audioplayer_service.dart b/lib/api/audio/audioplayer_service.dart index d865a62..23e77a6 100644 --- a/lib/api/audio/audioplayer_service.dart +++ b/lib/api/audio/audioplayer_service.dart @@ -79,6 +79,7 @@ class AudioPlayerService { themeNotifier.value = await ColorScheme.fromImageProvider( provider: CachedNetworkImageProvider( AudioPlayerService().song!.coverArtUrl, + cacheKey: AudioPlayerService().song!.coverArtId, ), ); logger.d(AudioPlayerService().song!.coverArtUrl); diff --git a/lib/api/subsonic/artist.dart b/lib/api/subsonic/artist.dart index 8d43314..399ab84 100644 --- a/lib/api/subsonic/artist.dart +++ b/lib/api/subsonic/artist.dart @@ -37,5 +37,5 @@ class Artist { final String artistImageUrl; /// Returns the cover art URL formed from the [coverArtId] - String get coverArt => SubsonicApiService().getCoverArtUrl(coverArtId); + String get coverArtUrl => SubsonicApiService().getCoverArtUrl(coverArtId); } diff --git a/lib/views/album_view.dart b/lib/views/album_view.dart index 0fb2877..edeeb46 100644 --- a/lib/views/album_view.dart +++ b/lib/views/album_view.dart @@ -43,6 +43,7 @@ class _AlbumViewState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ HeroBanner( + cacheKey: widget.album.coverArtId, imageUrl: widget.album.coverArtUrl, title: widget.album.name, description: widget.album.artistName, diff --git a/lib/views/artist_view.dart b/lib/views/artist_view.dart index c279581..bfa0ebb 100644 --- a/lib/views/artist_view.dart +++ b/lib/views/artist_view.dart @@ -45,7 +45,8 @@ class _ArtistViewState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ HeroBanner( - imageUrl: widget.artist.coverArt, + cacheKey: widget.artist.coverArtId, + imageUrl: widget.artist.coverArtUrl, title: widget.artist.name, description: "This could be a cool description soon", heroTag: widget.artist.name, @@ -69,6 +70,7 @@ class _ArtistViewState extends State { ); }, child: ImageCover( + cacheKey: _albums[n].coverArtId, imageUrl: _albums[n].coverArtUrl, title: _albums[n].name, heroTag: _albums[n].name, diff --git a/lib/views/home_view.dart b/lib/views/home_view.dart index 6aba11f..c95416c 100644 --- a/lib/views/home_view.dart +++ b/lib/views/home_view.dart @@ -118,7 +118,8 @@ class _HomeViewState extends State { ); }, child: ImageCover( - imageUrl: index.artists[n].coverArt, + cacheKey: index.artists[n].coverArtId, + imageUrl: index.artists[n].coverArtUrl, title: index.artists[n].name, heroTag: index.artists[n].name, ), diff --git a/lib/widgets/hero_banner.dart b/lib/widgets/hero_banner.dart index dc2e972..6ece765 100644 --- a/lib/widgets/hero_banner.dart +++ b/lib/widgets/hero_banner.dart @@ -11,12 +11,14 @@ class HeroBanner extends StatelessWidget { required this.title, required this.description, this.heroTag = "NotAHero", + this.cacheKey, super.key, }); final String imageUrl; final String title; final String description; final String heroTag; + final String? cacheKey; @override Widget build(BuildContext context) { return SizedBox( @@ -31,6 +33,7 @@ class HeroBanner extends StatelessWidget { tag: heroTag, child: CachedNetworkImage( imageUrl: imageUrl, + cacheKey: cacheKey, placeholder: (c, d) => Shimmer.fromColors( baseColor: Colors.grey.shade300, highlightColor: Colors.grey.shade100, diff --git a/lib/widgets/image_cover.dart b/lib/widgets/image_cover.dart index 0d9694e..5619e56 100644 --- a/lib/widgets/image_cover.dart +++ b/lib/widgets/image_cover.dart @@ -9,6 +9,7 @@ class ImageCover extends StatelessWidget { required this.imageUrl, required this.title, this.heroTag = "VeryUnconspicous", + this.cacheKey, super.key, }); @@ -16,6 +17,7 @@ class ImageCover extends StatelessWidget { final String title; final double _width = 180; final String heroTag; + final String? cacheKey; @override Widget build(BuildContext context) { return Column( @@ -28,6 +30,7 @@ class ImageCover extends StatelessWidget { child: ClipRRect( borderRadius: BorderRadius.circular(8), child: CachedNetworkImage( + cacheKey: cacheKey, imageUrl: imageUrl, placeholder: (c, d) => Shimmer.fromColors( baseColor: Colors.grey.shade300, diff --git a/lib/widgets/player.dart b/lib/widgets/player.dart index 101aa5b..efeda87 100644 --- a/lib/widgets/player.dart +++ b/lib/widgets/player.dart @@ -1,8 +1,5 @@ -import 'dart:convert'; - import 'package:auto_size_text/auto_size_text.dart'; import 'package:cached_network_image/cached_network_image.dart'; -import 'package:crypto/crypto.dart'; import 'package:flutter/material.dart'; import 'package:ocarina/api/audio/audioplayer_service.dart'; import 'package:ocarina/api/subsonic/song.dart'; @@ -101,15 +98,7 @@ class PlayerState extends State { ), ) : CachedNetworkImage( - key: Key( - md5 - .convert( - utf8.encode( - t.coverArtUrl, - ), - ) - .toString(), - ), + cacheKey: t.coverArtId, imageUrl: t.coverArtUrl, placeholder: (c, d) => Shimmer.fromColors( @@ -241,6 +230,7 @@ class PlayerState extends State { ), ) : (CachedNetworkImage( + cacheKey: AudioPlayerService().song!.coverArtId, imageUrl: AudioPlayerService().song!.coverArtUrl, placeholder: (c, d) => Shimmer.fromColors( diff --git a/lib/widgets/song_row.dart b/lib/widgets/song_row.dart index e536c9b..773aa23 100644 --- a/lib/widgets/song_row.dart +++ b/lib/widgets/song_row.dart @@ -4,9 +4,15 @@ import 'package:flutter/material.dart'; import 'package:text_scroll/text_scroll.dart'; class SongRow extends StatelessWidget { - const SongRow({required this.imageUrl, required this.songTitle, super.key}); + const SongRow({ + required this.imageUrl, + required this.songTitle, + this.cacheKey, + super.key, + }); final String imageUrl; final String songTitle; + final String? cacheKey; @override Widget build(BuildContext context) { return ClipRRect( @@ -18,7 +24,10 @@ class SongRow extends StatelessWidget { height: 100, child: ClipRRect( borderRadius: BorderRadius.circular(8), - child: CachedNetworkImage(imageUrl: imageUrl), + child: CachedNetworkImage( + imageUrl: imageUrl, + cacheKey: cacheKey, + ), ), ), title: AutoSizeText(