feat(playlists): Songs per Bottom-Sheet zu Playlisten hinzufügen
Ohne Eintrittspunkt wären Playlisten unbenutzbar, da sie sonst nie Songs
erhalten könnten. SongList bekommt einen zusätzlichen Trailing-Button
(Icons.playlist_add) neben dem Favoriten-Herz, der ein Bottom-Sheet mit
allen Playlisten öffnet ("Neue Playlist" oben, dann bestehende). Antippen
hängt den Song ans Ende der gewählten Playlist an und zeigt eine SnackBar.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
822384b39f
commit
fc9a6abdd7
@@ -2,9 +2,11 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../player/audio_handler.dart';
|
import '../player/audio_handler.dart';
|
||||||
|
import '../playlists/create_playlist_dialog.dart';
|
||||||
import '../shared/cover.dart';
|
import '../shared/cover.dart';
|
||||||
import '../shared/favorite_button.dart';
|
import '../shared/favorite_button.dart';
|
||||||
import 'database.dart';
|
import 'database.dart';
|
||||||
|
import 'playlist_service.dart';
|
||||||
import 'song_media.dart';
|
import 'song_media.dart';
|
||||||
|
|
||||||
/// Scrollbare Songliste; Tippen spielt die ganze Liste ab dem Song ab.
|
/// Scrollbare Songliste; Tippen spielt die ganze Liste ab dem Song ab.
|
||||||
@@ -12,6 +14,63 @@ class SongList extends StatelessWidget {
|
|||||||
const SongList(this.songs, {super.key});
|
const SongList(this.songs, {super.key});
|
||||||
final List<Song> songs;
|
final List<Song> songs;
|
||||||
|
|
||||||
|
/// Öffnet ein Bottom-Sheet mit allen Playlisten, um [song] hinzuzufügen.
|
||||||
|
Future<void> _showAddToPlaylist(BuildContext context, Song song) async {
|
||||||
|
final db = context.read<MeloDb>();
|
||||||
|
final service = context.read<PlaylistService>();
|
||||||
|
await showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (sheetContext) => SafeArea(
|
||||||
|
child: StreamBuilder<List<Playlist>>(
|
||||||
|
stream: db.watchPlaylists(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final playlists = snapshot.data ?? const [];
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.add),
|
||||||
|
title: const Text('Neue Playlist'),
|
||||||
|
onTap: () async {
|
||||||
|
final newId = await showDialog<String?>(
|
||||||
|
context: sheetContext,
|
||||||
|
builder: (_) => const CreatePlaylistDialog(),
|
||||||
|
);
|
||||||
|
if (newId == null) return;
|
||||||
|
final position = (await db.watchPlaylistSongs(newId).first).length;
|
||||||
|
await service.addSongToPlaylist(newId, song.id, position);
|
||||||
|
if (sheetContext.mounted) {
|
||||||
|
Navigator.pop(sheetContext);
|
||||||
|
ScaffoldMessenger.of(sheetContext).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Zu Playlist hinzugefügt')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
for (final playlist in playlists)
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.playlist_play),
|
||||||
|
title: Text(playlist.name),
|
||||||
|
onTap: () async {
|
||||||
|
final position =
|
||||||
|
(await db.watchPlaylistSongs(playlist.id).first).length;
|
||||||
|
await service.addSongToPlaylist(playlist.id, song.id, position);
|
||||||
|
if (sheetContext.mounted) {
|
||||||
|
Navigator.pop(sheetContext);
|
||||||
|
ScaffoldMessenger.of(sheetContext).showSnackBar(
|
||||||
|
SnackBar(content: Text('Zu ${playlist.name} hinzugefügt')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final handler = context.read<MeloAudioHandler>();
|
final handler = context.read<MeloAudioHandler>();
|
||||||
@@ -28,7 +87,17 @@ class SongList extends StatelessWidget {
|
|||||||
title: Text(s.title, maxLines: 1, overflow: TextOverflow.ellipsis),
|
title: Text(s.title, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||||
subtitle: Text(s.artist ?? 'Unbekannt',
|
subtitle: Text(s.artist ?? 'Unbekannt',
|
||||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||||
trailing: FavoriteButton(songId: s.id),
|
trailing: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
FavoriteButton(songId: s.id),
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'Zu Playlist hinzufügen',
|
||||||
|
icon: const Icon(Icons.playlist_add),
|
||||||
|
onPressed: () => _showAddToPlaylist(context, s),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
try {
|
try {
|
||||||
await playSongs(handler, songs, i);
|
await playSongs(handler, songs, i);
|
||||||
|
|||||||
Reference in New Issue
Block a user