From 1fa3a5077bb3b2990dfd236dcea7aaa616d11af9 Mon Sep 17 00:00:00 2001 From: Feichtmeier Date: Wed, 15 May 2024 22:41:07 +0200 Subject: [PATCH] Newly created playlists doesn't show up Fixes #740 --- .../view/add_to_playlist_dialog.dart | 67 ++++++++++++------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/lib/src/playlists/view/add_to_playlist_dialog.dart b/lib/src/playlists/view/add_to_playlist_dialog.dart index 8c0a45f38..eb154c251 100644 --- a/lib/src/playlists/view/add_to_playlist_dialog.dart +++ b/lib/src/playlists/view/add_to_playlist_dialog.dart @@ -3,6 +3,7 @@ import 'package:yaru/yaru.dart'; import '../../../common.dart'; import '../../../data.dart'; +import '../../../get.dart'; import '../../../globals.dart'; import '../../../l10n.dart'; import '../../../library.dart'; @@ -25,38 +26,13 @@ class AddToPlaylistDialog extends StatelessWidget { key: playlistNavigatorKey, initialRoute: '/', onGenerateRoute: (settings) { - final listView = ListView( - shrinkWrap: true, - children: [ - ListTile( - onTap: () => playlistNavigatorKey.currentState?.pushNamed('/new'), - leading: SideBarFallBackImage( - color: Colors.transparent, - child: Icon(Iconz().plus), - ), - title: Text(context.l10n.createNewPlaylist), - ), - ...libraryModel.getPlaylistNames().map( - (playlistId) => Builder( - builder: (context) { - return _PlaylistTile( - playlistId: playlistId, - libraryModel: libraryModel, - audio: audio, - ); - }, - ), - ), - ], - ); - return PageRouteBuilder( pageBuilder: (_, __, ___) => settings.name == '/new' ? _NewView( libraryModel: libraryModel, audio: audio, ) - : listView, + : _PlaylistTilesList(audio: audio), transitionDuration: const Duration(milliseconds: 500), ); }, @@ -77,6 +53,45 @@ class AddToPlaylistDialog extends StatelessWidget { } } +class _PlaylistTilesList extends StatelessWidget with WatchItMixin { + const _PlaylistTilesList({ + required this.audio, + }); + + final Audio audio; + + @override + Widget build(BuildContext context) { + final playlistNames = watchPropertyValue( + (LibraryModel m) => m.playlists.keys.map((e) => e.toString()), + ); + return ListView( + shrinkWrap: true, + children: [ + ListTile( + onTap: () => playlistNavigatorKey.currentState?.pushNamed('/new'), + leading: SideBarFallBackImage( + color: Colors.transparent, + child: Icon(Iconz().plus), + ), + title: Text(context.l10n.createNewPlaylist), + ), + ...playlistNames.map( + (playlistId) => Builder( + builder: (context) { + return _PlaylistTile( + playlistId: playlistId, + libraryModel: getIt(), + audio: audio, + ); + }, + ), + ), + ], + ); + } +} + class _PlaylistTile extends StatelessWidget { const _PlaylistTile({ required this.libraryModel,