- Filled heart when favorited, outline when not (reactive via watchIsFavorite) - Wired into every song list tile (library, search, playlists) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
32 lines
1.0 KiB
Dart
32 lines
1.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../library/database.dart';
|
|
import '../library/playlist_service.dart';
|
|
import 'theme.dart';
|
|
|
|
/// Herz-Toggle: ausgefüllt = favorisiert, umrandet = nicht favorisiert.
|
|
class FavoriteButton extends StatelessWidget {
|
|
const FavoriteButton({super.key, required this.songId});
|
|
final String songId;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final db = context.read<MeloDb>();
|
|
final service = context.read<PlaylistService>();
|
|
return StreamBuilder<bool>(
|
|
stream: db.watchIsFavorite(songId),
|
|
builder: (context, snapshot) {
|
|
final isFavorite = snapshot.data ?? false;
|
|
return IconButton(
|
|
tooltip: isFavorite ? 'Favorit entfernen' : 'Zu Favoriten hinzufügen',
|
|
icon: Icon(
|
|
isFavorite ? Icons.favorite : Icons.favorite_border,
|
|
color: isFavorite ? MeloTheme.red : Colors.white54,
|
|
),
|
|
onPressed: () => service.toggleFavorite(songId),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|