mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 23:02:43 +01:00
cover art color scheme extraction (in background)
refactor text styles to use theme port over part of album screen
This commit is contained in:
56
lib/app/ui/cover_art_theme.dart
Normal file
56
lib/app/ui/cover_art_theme.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
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 '../state/source.dart';
|
||||
import '../util/color_scheme.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
class CoverArtTheme extends HookConsumerWidget {
|
||||
const CoverArtTheme({
|
||||
super.key,
|
||||
required this.coverArt,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final String? coverArt;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final source = ref.watch(sourceProvider);
|
||||
final sourceId = ref.watch(sourceIdProvider);
|
||||
|
||||
final getColorScheme = useMemoized(
|
||||
() async {
|
||||
try {
|
||||
return await colorSchemefromImageProvider(
|
||||
brightness: Brightness.dark,
|
||||
provider: CachedNetworkImageProvider(
|
||||
coverArt != null
|
||||
? source.coverArtUri(coverArt!, thumbnail: true).toString()
|
||||
: 'https://placehold.net/400x400.png',
|
||||
cacheKey: coverArt != null
|
||||
? '$sourceId$coverArt${true}'
|
||||
: 'https://placehold.net/400x400.png',
|
||||
),
|
||||
);
|
||||
} catch (err) {
|
||||
print(err);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
[source, sourceId, coverArt],
|
||||
);
|
||||
|
||||
final colorScheme = useFuture(getColorScheme).data;
|
||||
|
||||
return colorScheme != null
|
||||
? Theme(
|
||||
data: subtracksTheme(colorScheme),
|
||||
child: child,
|
||||
)
|
||||
: child;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user