mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00

track Share popup menu not showing when not logged in fix page tranistions changed to default material 3 design's Wrong link in Login page fix Changing UserPreferences provider resets the Playback provider using using hookified_infinite_scroll_pagination officially
41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:palette_generator/palette_generator.dart';
|
|
|
|
final _paletteColorState = StateProvider<PaletteColor>(
|
|
(ref) {
|
|
return PaletteColor(Colors.grey[300]!, 0);
|
|
},
|
|
);
|
|
|
|
PaletteColor usePaletteColor(
|
|
BuildContext context, String imageUrl, WidgetRef ref) {
|
|
final paletteColor = ref.watch(_paletteColorState);
|
|
final mounted = useIsMounted();
|
|
|
|
useEffect(() {
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
|
final palette = await PaletteGenerator.fromImageProvider(
|
|
CachedNetworkImageProvider(
|
|
imageUrl,
|
|
cacheKey: imageUrl,
|
|
maxHeight: 50,
|
|
maxWidth: 50,
|
|
),
|
|
);
|
|
if (!mounted()) return;
|
|
final color = Theme.of(context).brightness == Brightness.light
|
|
? palette.lightMutedColor ?? palette.lightVibrantColor
|
|
: palette.darkMutedColor ?? palette.darkVibrantColor;
|
|
if (color != null) {
|
|
ref.read(_paletteColorState.notifier).state = color;
|
|
}
|
|
});
|
|
return null;
|
|
}, [imageUrl]);
|
|
|
|
return paletteColor;
|
|
}
|