spotube/lib/components/heart_button/heart_button.dart
Kingkor Roy Tirtho 5567214588
feat: add new icons #2676 by @alexio-dev (#2678)
* feat: add new improved logo

* feat: add new improved logo

* feat: add new improved logo

* feat: add new improved logo

* chore: update the logos in app

* Merge branch 'alexio-dev-refactor/new-icons' into refactor/new-icons #2676

* chore: generate icons for every flavor

* chore: add readme banner

* chore: add back deleted images

* chore: update native splash screen

* chore: fix dart analyzer warnings
2025-04-25 21:55:59 +06:00

95 lines
2.6 KiB
Dart

import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/components/heart_button/use_track_toggle_like.dart';
import 'package:spotube/extensions/context.dart';
import 'package:spotube/provider/authentication/authentication.dart';
import 'package:spotube/provider/spotify/spotify.dart';
class HeartButton extends HookConsumerWidget {
final bool isLiked;
final void Function()? onPressed;
final IconData? icon;
final Color? color;
final String? tooltip;
final AbstractButtonStyle variance;
final ButtonSize size;
const HeartButton({
required this.isLiked,
required this.onPressed,
this.color,
this.tooltip,
this.icon,
this.variance = ButtonVariance.ghost,
this.size = ButtonSize.normal,
super.key,
});
@override
Widget build(BuildContext context, ref) {
final auth = ref.watch(authenticationProvider);
if (auth.asData?.value == null) return const SizedBox.shrink();
return Tooltip(
tooltip: TooltipContainer(child: Text(tooltip ?? "")).call,
child: IconButton(
variance: variance,
size: size,
icon: AnimatedSwitcher(
switchInCurve: Curves.fastOutSlowIn,
switchOutCurve: Curves.fastOutSlowIn,
duration: const Duration(milliseconds: 300),
transitionBuilder: (child, animation) {
return ScaleTransition(
scale: animation,
child: child,
);
},
child: Icon(
icon ??
(isLiked
? Icons.favorite_rounded
: Icons.favorite_outline_rounded),
key: ValueKey(isLiked),
color: color ?? (isLiked ? color ?? Colors.red : null),
),
),
onPressed: onPressed,
),
);
}
}
class TrackHeartButton extends HookConsumerWidget {
final Track track;
const TrackHeartButton({
super.key,
required this.track,
});
@override
Widget build(BuildContext context, ref) {
final savedTracks = ref.watch(likedTracksProvider);
final me = ref.watch(meProvider);
final (:isLiked, :toggleTrackLike) = useTrackToggleLike(track, ref);
if (me.isLoading) {
return const CircularProgressIndicator();
}
return HeartButton(
tooltip: isLiked
? context.l10n.remove_from_favorites
: context.l10n.save_as_favorite,
isLiked: isLiked,
onPressed: savedTracks.asData?.value != null
? () {
toggleTrackLike(track);
}
: null,
);
}
}