fix: actual caching

fixes #1
This commit is contained in:
Matyáš Caras 2024-05-28 18:54:05 +02:00
parent 35b6d042f9
commit 773cf12b97
Signed by: hernik
GPG key ID: 2A3175F98820C5C6
9 changed files with 27 additions and 17 deletions

View file

@ -79,6 +79,7 @@ class AudioPlayerService {
themeNotifier.value = await ColorScheme.fromImageProvider( themeNotifier.value = await ColorScheme.fromImageProvider(
provider: CachedNetworkImageProvider( provider: CachedNetworkImageProvider(
AudioPlayerService().song!.coverArtUrl, AudioPlayerService().song!.coverArtUrl,
cacheKey: AudioPlayerService().song!.coverArtId,
), ),
); );
logger.d(AudioPlayerService().song!.coverArtUrl); logger.d(AudioPlayerService().song!.coverArtUrl);

View file

@ -37,5 +37,5 @@ class Artist {
final String artistImageUrl; final String artistImageUrl;
/// Returns the cover art URL formed from the [coverArtId] /// Returns the cover art URL formed from the [coverArtId]
String get coverArt => SubsonicApiService().getCoverArtUrl(coverArtId); String get coverArtUrl => SubsonicApiService().getCoverArtUrl(coverArtId);
} }

View file

@ -43,6 +43,7 @@ class _AlbumViewState extends State<AlbumView> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
HeroBanner( HeroBanner(
cacheKey: widget.album.coverArtId,
imageUrl: widget.album.coverArtUrl, imageUrl: widget.album.coverArtUrl,
title: widget.album.name, title: widget.album.name,
description: widget.album.artistName, description: widget.album.artistName,

View file

@ -45,7 +45,8 @@ class _ArtistViewState extends State<ArtistView> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
HeroBanner( HeroBanner(
imageUrl: widget.artist.coverArt, cacheKey: widget.artist.coverArtId,
imageUrl: widget.artist.coverArtUrl,
title: widget.artist.name, title: widget.artist.name,
description: "This could be a cool description soon", description: "This could be a cool description soon",
heroTag: widget.artist.name, heroTag: widget.artist.name,
@ -69,6 +70,7 @@ class _ArtistViewState extends State<ArtistView> {
); );
}, },
child: ImageCover( child: ImageCover(
cacheKey: _albums[n].coverArtId,
imageUrl: _albums[n].coverArtUrl, imageUrl: _albums[n].coverArtUrl,
title: _albums[n].name, title: _albums[n].name,
heroTag: _albums[n].name, heroTag: _albums[n].name,

View file

@ -118,7 +118,8 @@ class _HomeViewState extends State<HomeView> {
); );
}, },
child: ImageCover( child: ImageCover(
imageUrl: index.artists[n].coverArt, cacheKey: index.artists[n].coverArtId,
imageUrl: index.artists[n].coverArtUrl,
title: index.artists[n].name, title: index.artists[n].name,
heroTag: index.artists[n].name, heroTag: index.artists[n].name,
), ),

View file

@ -11,12 +11,14 @@ class HeroBanner extends StatelessWidget {
required this.title, required this.title,
required this.description, required this.description,
this.heroTag = "NotAHero", this.heroTag = "NotAHero",
this.cacheKey,
super.key, super.key,
}); });
final String imageUrl; final String imageUrl;
final String title; final String title;
final String description; final String description;
final String heroTag; final String heroTag;
final String? cacheKey;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SizedBox( return SizedBox(
@ -31,6 +33,7 @@ class HeroBanner extends StatelessWidget {
tag: heroTag, tag: heroTag,
child: CachedNetworkImage( child: CachedNetworkImage(
imageUrl: imageUrl, imageUrl: imageUrl,
cacheKey: cacheKey,
placeholder: (c, d) => Shimmer.fromColors( placeholder: (c, d) => Shimmer.fromColors(
baseColor: Colors.grey.shade300, baseColor: Colors.grey.shade300,
highlightColor: Colors.grey.shade100, highlightColor: Colors.grey.shade100,

View file

@ -9,6 +9,7 @@ class ImageCover extends StatelessWidget {
required this.imageUrl, required this.imageUrl,
required this.title, required this.title,
this.heroTag = "VeryUnconspicous", this.heroTag = "VeryUnconspicous",
this.cacheKey,
super.key, super.key,
}); });
@ -16,6 +17,7 @@ class ImageCover extends StatelessWidget {
final String title; final String title;
final double _width = 180; final double _width = 180;
final String heroTag; final String heroTag;
final String? cacheKey;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
@ -28,6 +30,7 @@ class ImageCover extends StatelessWidget {
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
child: CachedNetworkImage( child: CachedNetworkImage(
cacheKey: cacheKey,
imageUrl: imageUrl, imageUrl: imageUrl,
placeholder: (c, d) => Shimmer.fromColors( placeholder: (c, d) => Shimmer.fromColors(
baseColor: Colors.grey.shade300, baseColor: Colors.grey.shade300,

View file

@ -1,8 +1,5 @@
import 'dart:convert';
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ocarina/api/audio/audioplayer_service.dart'; import 'package:ocarina/api/audio/audioplayer_service.dart';
import 'package:ocarina/api/subsonic/song.dart'; import 'package:ocarina/api/subsonic/song.dart';
@ -101,15 +98,7 @@ class PlayerState extends State<Player> {
), ),
) )
: CachedNetworkImage( : CachedNetworkImage(
key: Key( cacheKey: t.coverArtId,
md5
.convert(
utf8.encode(
t.coverArtUrl,
),
)
.toString(),
),
imageUrl: t.coverArtUrl, imageUrl: t.coverArtUrl,
placeholder: (c, d) => placeholder: (c, d) =>
Shimmer.fromColors( Shimmer.fromColors(
@ -241,6 +230,7 @@ class PlayerState extends State<Player> {
), ),
) )
: (CachedNetworkImage( : (CachedNetworkImage(
cacheKey: AudioPlayerService().song!.coverArtId,
imageUrl: imageUrl:
AudioPlayerService().song!.coverArtUrl, AudioPlayerService().song!.coverArtUrl,
placeholder: (c, d) => Shimmer.fromColors( placeholder: (c, d) => Shimmer.fromColors(

View file

@ -4,9 +4,15 @@ import 'package:flutter/material.dart';
import 'package:text_scroll/text_scroll.dart'; import 'package:text_scroll/text_scroll.dart';
class SongRow extends StatelessWidget { 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 imageUrl;
final String songTitle; final String songTitle;
final String? cacheKey;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ClipRRect( return ClipRRect(
@ -18,7 +24,10 @@ class SongRow extends StatelessWidget {
height: 100, height: 100,
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
child: CachedNetworkImage(imageUrl: imageUrl), child: CachedNetworkImage(
imageUrl: imageUrl,
cacheKey: cacheKey,
),
), ),
), ),
title: AutoSizeText( title: AutoSizeText(