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(
provider: CachedNetworkImageProvider(
AudioPlayerService().song!.coverArtUrl,
cacheKey: AudioPlayerService().song!.coverArtId,
),
);
logger.d(AudioPlayerService().song!.coverArtUrl);

View file

@ -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);
}

View file

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

View file

@ -45,7 +45,8 @@ class _ArtistViewState extends State<ArtistView> {
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<ArtistView> {
);
},
child: ImageCover(
cacheKey: _albums[n].coverArtId,
imageUrl: _albums[n].coverArtUrl,
title: _albums[n].name,
heroTag: _albums[n].name,

View file

@ -118,7 +118,8 @@ class _HomeViewState extends State<HomeView> {
);
},
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,
),

View file

@ -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,

View file

@ -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,

View file

@ -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<Player> {
),
)
: 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<Player> {
),
)
: (CachedNetworkImage(
cacheKey: AudioPlayerService().song!.coverArtId,
imageUrl:
AudioPlayerService().song!.coverArtUrl,
placeholder: (c, d) => Shimmer.fromColors(

View file

@ -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(