mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 23:02:43 +01:00
display albums from db
This commit is contained in:
52
lib/images/images.dart
Normal file
52
lib/images/images.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:octo_image/octo_image.dart';
|
||||
|
||||
import '../app/state/source.dart';
|
||||
|
||||
class CoverArtImage extends HookConsumerWidget {
|
||||
const CoverArtImage({
|
||||
super.key,
|
||||
this.coverArt,
|
||||
this.thumbnail = false,
|
||||
});
|
||||
|
||||
final String? coverArt;
|
||||
final bool thumbnail;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final source = ref.watch(sourceProvider);
|
||||
|
||||
final imageProviderKeys = [source, coverArt, thumbnail];
|
||||
final buildImageProvider = useCallback(
|
||||
() => CachedNetworkImageProvider(
|
||||
coverArt != null
|
||||
? source.coverArtUri(coverArt!, thumbnail: thumbnail).toString()
|
||||
: 'https://placehold.net/400x400.png',
|
||||
),
|
||||
imageProviderKeys,
|
||||
);
|
||||
|
||||
final imageProvider = useState(buildImageProvider());
|
||||
useEffect(
|
||||
() {
|
||||
imageProvider.value = buildImageProvider();
|
||||
return;
|
||||
},
|
||||
imageProviderKeys,
|
||||
);
|
||||
|
||||
return OctoImage(
|
||||
image: imageProvider.value,
|
||||
placeholderBuilder: (context) => Icon(Symbols.album_rounded),
|
||||
errorBuilder: (context, error, trace) => Icon(Icons.error),
|
||||
fit: BoxFit.cover,
|
||||
fadeOutDuration: Duration(milliseconds: 100),
|
||||
fadeInDuration: Duration(milliseconds: 200),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user