Skip to content

Commit 4735588

Browse files
committed
Feat: Add artist to queue button
1 parent efd8798 commit 4735588

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

lib/providers/player_provider.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,11 @@ class PlayerProvider extends ChangeNotifier {
12551255
notifyListeners();
12561256
}
12571257

1258+
void addAllToQueue(Iterable<Song> songs) {
1259+
_queue.addAll(songs);
1260+
notifyListeners();
1261+
}
1262+
12581263
void removeFromQueue(int index) {
12591264
if (index >= 0 && index < _queue.length) {
12601265
_queue.removeAt(index);

lib/screens/artist_screen.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,48 @@ class _ArtistScreenState extends State<ArtistScreen> {
7474
}
7575
}
7676

77+
Future<void> _addArtistToQueue() async {
78+
if (_albums.isEmpty) return;
79+
80+
final playerProvider = Provider.of<PlayerProvider>(context, listen: false);
81+
final libraryProvider = Provider.of<LibraryProvider>(context, listen: false);
82+
final subsonicService = libraryProvider.subsonicService;
83+
final messenger = ScaffoldMessenger.of(context);
84+
85+
try {
86+
final songsToQueue = <Song>[];
87+
for (final album in _albums) {
88+
final albumSongs = libraryProvider.isLocalOnlyMode
89+
? libraryProvider.cachedAllSongs
90+
.where((s) => s.albumId == album.id)
91+
.toList()
92+
: await subsonicService.getAlbumSongs(album.id);
93+
94+
songsToQueue.addAll(albumSongs);
95+
}
96+
97+
if (songsToQueue.isNotEmpty) {
98+
playerProvider.addAllToQueue(songsToQueue);
99+
}
100+
// Show snackbar on success?
101+
102+
// messenger.showSnackBar(
103+
// SnackBar(
104+
// content: Text(AppLocalizations.of(context)!.addToQueue),
105+
// duration: const Duration(seconds: 2),
106+
// ),
107+
// );
108+
} catch (e) {
109+
if (!mounted) return;
110+
messenger.showSnackBar(
111+
SnackBar(
112+
content: Text('Error adding to queue: $e'), //Add localization for this error msg?
113+
duration: const Duration(seconds: 2),
114+
),
115+
);
116+
}
117+
}
118+
77119
void _playTopSongs({bool shuffle = false}) {
78120
if (_topSongs.isEmpty) return;
79121

@@ -144,6 +186,11 @@ class _ArtistScreenState extends State<ArtistScreen> {
144186
),
145187
),
146188
actions: [
189+
IconButton(
190+
icon: const Icon(Icons.queue_music_rounded),
191+
tooltip: AppLocalizations.of(context)!.addToQueue,
192+
onPressed: _albums.isEmpty ? null : () => _addArtistToQueue(),
193+
),
147194
IconButton(
148195
icon: const Icon(CupertinoIcons.play_circle_fill),
149196
onPressed: () => _playTopSongs(),

0 commit comments

Comments
 (0)