@@ -505,7 +505,11 @@ class _PlaylistPageState extends State<PlaylistPage> {
505505 }
506506
507507 Widget _buildDownloadButton () {
508- final playlistId = widget.playlistId ?? _playlist['title' ];
508+ final playlistId = _playlist? ['ytid' ]? .toString () ?? widget.playlistId;
509+
510+ if (playlistId == null || playlistId.isEmpty) {
511+ return const SizedBox .shrink ();
512+ }
509513
510514 return ValueListenableBuilder <List <dynamic >>(
511515 valueListenable: offlinePlaylistService.offlinePlaylists,
@@ -587,31 +591,24 @@ class _PlaylistPageState extends State<PlaylistPage> {
587591 showRemoveOfflinePlaylistDialog (context, playlistId);
588592
589593 void _handleSyncPlaylist () async {
590- if (_playlist['ytid' ] != null ) {
591- final updated = await updatePlaylistList (context, _playlist['ytid' ]);
592- if (updated != null && mounted) {
593- setState (() {
594- _playlist = updated;
595- if (_playlist['list' ] != null ) {
596- _originalPlaylistList = List <dynamic >.from (
597- _playlist['list' ] as List ,
598- );
599- }
600- });
601- }
602- } else {
603- final resolvedId = _playlist['ytid' ]? .toString () ?? widget.playlistId;
604- final updatedPlaylist = await getPlaylistInfoForWidget (resolvedId);
605- if (updatedPlaylist != null && mounted) {
606- setState (() {
607- _playlist = updatedPlaylist;
608- if (_playlist['list' ] != null ) {
609- _originalPlaylistList = List <dynamic >.from (
610- _playlist['list' ] as List ,
611- );
612- }
613- });
594+ final playlistId = _playlist? ['ytid' ]? .toString ();
595+ if (playlistId == null || playlistId.isEmpty) return ;
596+
597+ if (offlinePlaylistService.isPlaylistDownloaded (playlistId)) {
598+ if (mounted) {
599+ showToast (context, context.l10n! .removeOffline);
614600 }
601+ return ;
602+ }
603+
604+ final updated = await updatePlaylistList (context, playlistId);
605+ if (updated != null && mounted) {
606+ setState (() {
607+ _playlist = updated;
608+ if (_playlist['list' ] != null ) {
609+ _originalPlaylistList = List <dynamic >.from (_playlist['list' ] as List );
610+ }
611+ });
615612 }
616613 }
617614
0 commit comments