Files
Melo/lib/playlists/playlists_screen.dart
T
Hermes (Server) 07acf77ba4 UX-Simulation: Mehrfachauswahl überall, Baka-Login, Bestätigungen, Suche
7 Agenten sind die App als normaler Nutzer durchgegangen (Erststart,
Bibliothek, Download, Suche, Favoriten, Player, Einstellungen) und haben
39 Reibungspunkte gefunden. Erster Block:

- Mehrfachauswahl lief nur im Lieder-/Favoriten-Reiter, nicht in
  Kategorie-/Künstler-/Album-Ansichten — jetzt überall, per geteilter
  auswahl_leiste.dart
- Zwei unterschiedlich ausgestattete Favoriten-Listen (Tab vs. Playlisten)
  vereinheitlicht
- Baka-Login zeigt Ladezustand + Fehler im Dialog statt bis zu 15s stumm
  zu bleiben (wie der Navidrome-Login)
- Cache leeren, Navidrome-Abmelden, Download einzeln entfernen fragen jetzt
  nach
- Download-Fehlermeldung bei toter Serververbindung nennt den echten Grund
  statt "War schon heruntergeladen"
- YouTube-Fehlermeldungen sind jetzt rot statt neutralfarben
- Suche schließt die Tastatur nach Auswahl, nennt den Suchbegriff bei
  "Nichts gefunden", einzelne Verlaufseinträge sind entfernbar
- Icon-/Text-Korrekturen (Mikrofon-Icon fälschlich bei Speicherzugriff,
  "Online"-Tab existiert nicht, ReplayGain-Jargon)

537 Tests grün (vorher 533), flutter analyze ohne Befund.
2026-08-25 09:42:41 +02:00

179 lines
5.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../library/database.dart';
import '../library/playlist_service.dart';
import '../shared/sort_store.dart';
import '../shared/sortable_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: MeloTheme.text2)),
);
}
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: MeloTheme.text2)),
SizedBox(height: 8),
Text('Tippe auf + um eine Playlist zu erstellen',
style: TextStyle(color: MeloTheme.text3, fontSize: 12)),
],
),
);
}
}
/// Gepushte Ansicht der favorisierten Songs.
///
/// Dieselbe [SortableSongList] wie im Favoriten-Tab (Shuffle, Sortieren,
/// Mehrfachauswahl) — vorher stand hier eine nackte [SongList] ohne all das,
/// obwohl es dieselben Songs sind wie im Tab.
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 <Song>[];
return SortableSongList(
songs: songs,
storeKey: SortStore.favoriten,
empty: const Center(
child: Text('Noch keine Favoriten',
style: TextStyle(color: MeloTheme.text2)),
),
);
},
),
);
}
}