@@ -169,10 +169,6 @@ class OfflinePlaylistService {
169169 if (! completer.isCompleted) {
170170 completer.complete ();
171171 }
172- } else if (songQueue.isNotEmpty &&
173- ! progressNotifier.value.isCancelled) {
174- // Start next song if available
175- unawaited (processQueue ());
176172 } else if (songQueue.isEmpty && runningTasks == 0 ) {
177173 // All tasks completed
178174 if (! completer.isCompleted) {
@@ -215,7 +211,9 @@ class OfflinePlaylistService {
215211 stackTrace: stackTrace,
216212 );
217213 activeDownloads.remove (playlistId);
218- showToast (context, '${context .l10n !.error }: $e ' );
214+ if (context.mounted) {
215+ showToast (context, '${context .l10n !.error }: $e ' );
216+ }
219217 }
220218 }
221219
@@ -266,18 +264,24 @@ class OfflinePlaylistService {
266264 ),
267265 );
268266
269- showToast (
270- context,
271- '${context .l10n !.playlistDownloaded }: ${progressNotifier .value .completed }/${songsList .length }' ,
272- );
273- } else if (progressNotifier.value.isCancelled) {
274- showToast (context, context.l10n! .downloadCancelled);
275- } else {
276- showToast (
277- context,
278- '${context .l10n !.downloadFailed }: ${progressNotifier .value .failed }/${songsList .length }' ,
279- );
267+ if (context.mounted) {
268+ showToast (
269+ context,
270+ '${context .l10n !.playlistDownloaded }: ${progressNotifier .value .completed }/${songsList .length }' ,
271+ );
272+ }
273+ } else if (! progressNotifier.value.isCancelled) {
274+ // Cancelled toast is shown by cancelDownload, only show failure toast here.
275+ if (context.mounted) {
276+ showToast (
277+ context,
278+ '${context .l10n !.downloadFailed }: ${progressNotifier .value .failed }/${songsList .length }' ,
279+ );
280+ }
280281 }
282+
283+ // Clean up the progress notifier now that the download is fully done.
284+ cleanupProgressNotifier (playlistId);
281285 } catch (e, stackTrace) {
282286 logger.log (
283287 'Error handling download completion' ,
0 commit comments