- PlaylistsScreen: Favoriten-ListTile oben (watchFavorites, pusht FavoritesListScreen), darunter alle Playlisten (watchPlaylists) mit Songanzahl, Löschen via Icon/Long-Press + Bestätigungsdialog - CreatePlaylistDialog: Name-Eingabe, Erstellen-Button erst aktiv bei nicht-leerem Text, gibt die neue Playlist-ID zurück - Leer-Zustand "Noch keine Playlisten" nach Vorbild von library_screen.dart - main.dart: Playlisten-Platzhalter durch PlaylistsScreen ersetzt Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
172 lines
5.3 KiB
Dart
172 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../library/database.dart';
|
|
import '../library/playlist_service.dart';
|
|
import '../library/song_list.dart';
|
|
import '../shared/theme.dart';
|
|
import 'create_playlist_dialog.dart';
|
|
import 'playlist_detail_screen.dart';
|
|
|
|
/// Playlisten-Tab: Favoriten-Kurzeinstieg oben, darunter alle eigenen Playlisten.
|
|
class PlaylistsScreen extends StatelessWidget {
|
|
const PlaylistsScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final db = context.read<MeloDb>();
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Playlisten')),
|
|
body: Column(
|
|
children: [
|
|
StreamBuilder<List<Song>>(
|
|
stream: db.watchFavorites(),
|
|
builder: (context, snapshot) {
|
|
final count = snapshot.data?.length ?? 0;
|
|
return ListTile(
|
|
leading: const Icon(Icons.favorite, color: MeloTheme.red),
|
|
title: const Text('Favoriten'),
|
|
subtitle: Text('$count Songs'),
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (_) => const FavoritesListScreen()),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
const Divider(height: 1),
|
|
Expanded(
|
|
child: StreamBuilder<List<Playlist>>(
|
|
stream: db.watchPlaylists(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasError) {
|
|
return Center(
|
|
child: Text('Fehler: ${snapshot.error}',
|
|
style: const TextStyle(color: Colors.white54)),
|
|
);
|
|
}
|
|
final playlists = snapshot.data ?? const [];
|
|
if (playlists.isEmpty) {
|
|
return const _Empty();
|
|
}
|
|
return ListView.builder(
|
|
itemCount: playlists.length,
|
|
itemBuilder: (context, i) => _PlaylistTile(playlist: playlists[i]),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
tooltip: 'Neue Playlist',
|
|
onPressed: () => showDialog<String?>(
|
|
context: context,
|
|
builder: (_) => const CreatePlaylistDialog(),
|
|
),
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PlaylistTile extends StatelessWidget {
|
|
const _PlaylistTile({required this.playlist});
|
|
final Playlist playlist;
|
|
|
|
Future<void> _confirmDelete(BuildContext context) async {
|
|
final confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: const Text('Playlist löschen?'),
|
|
content: Text('„${playlist.name}“ wird dauerhaft gelöscht.'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(ctx, false),
|
|
child: const Text('Abbrechen'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(ctx, true),
|
|
child: const Text('Löschen'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (confirmed == true && context.mounted) {
|
|
await context.read<PlaylistService>().deletePlaylist(playlist.id);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final db = context.read<MeloDb>();
|
|
return StreamBuilder<List<Song>>(
|
|
stream: db.watchPlaylistSongs(playlist.id),
|
|
builder: (context, snapshot) {
|
|
final count = snapshot.data?.length ?? 0;
|
|
return ListTile(
|
|
leading: const Icon(Icons.playlist_play),
|
|
title: Text(playlist.name),
|
|
subtitle: Text('$count Songs'),
|
|
trailing: IconButton(
|
|
tooltip: 'Playlist löschen',
|
|
icon: const Icon(Icons.delete_outline),
|
|
onPressed: () => _confirmDelete(context),
|
|
),
|
|
onLongPress: () => _confirmDelete(context),
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (_) => PlaylistDetailScreen(playlist: playlist)),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Empty extends StatelessWidget {
|
|
const _Empty();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.playlist_play, size: 64, color: Colors.white24),
|
|
SizedBox(height: 12),
|
|
Text('Noch keine Playlisten', style: TextStyle(color: Colors.white54)),
|
|
SizedBox(height: 8),
|
|
Text('Tippe auf + um eine Playlist zu erstellen',
|
|
style: TextStyle(color: Colors.white38, fontSize: 12)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Gepushte Ansicht der favorisierten Songs.
|
|
class FavoritesListScreen extends StatelessWidget {
|
|
const FavoritesListScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final db = context.read<MeloDb>();
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Favoriten')),
|
|
body: StreamBuilder<List<Song>>(
|
|
stream: db.watchFavorites(),
|
|
builder: (context, snapshot) {
|
|
final songs = snapshot.data ?? const [];
|
|
if (songs.isEmpty) {
|
|
return const Center(
|
|
child: Text('Noch keine Favoriten', style: TextStyle(color: Colors.white54)),
|
|
);
|
|
}
|
|
return SongList(songs);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|