From 22bf491fb19f5ef00845cd37223a9326318f8fce Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Sun, 4 Feb 2024 00:15:18 +0530 Subject: [PATCH] library repeated list fix --- .../library/cubit/library_items_cubit.dart | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/blocs/library/cubit/library_items_cubit.dart b/lib/blocs/library/cubit/library_items_cubit.dart index 7a4845c..63b4f0a 100644 --- a/lib/blocs/library/cubit/library_items_cubit.dart +++ b/lib/blocs/library/cubit/library_items_cubit.dart @@ -32,26 +32,26 @@ class LibraryItemsCubit extends Cubit { } Future getAndEmitPlaylists() async { + List _playlists = List.empty(growable: true); libraryItemsState = LibraryItemsState(playlists: List.empty(growable: true)); mediaPlaylist = await mediaDBCubit.getListOfPlaylists2(); - List _playlists = List.empty(growable: true); + // List _playlists = List.empty(growable: true); + + // if (libraryItemsState.playlists.isNotEmpty) { + // for (var element in libraryItemsState.playlists) { + // _playlists.add(element.playlistName ?? "Unknown"); + // } + // libraryItemsState.playlists = []; + // } + libraryItemsState.playlists.clear(); + log("emitted from library0 ${_playlists.length} - MediaPlaylists ${mediaPlaylist.length}", + name: "libItemsCubit"); - if (libraryItemsState.playlists.isNotEmpty) { - for (var element in libraryItemsState.playlists) { - _playlists.add(element.playlistName ?? "Unknown"); - } - libraryItemsState.playlists = []; - } if (mediaPlaylist.length > 0) { for (var element in mediaPlaylist) { - // if (_playlists.contains(element.albumName)) { - // int? _idx = _playlists.indexOf(element.albumName); - - // libraryItemsState.playlists.removeAt(_idx); - // } ImageProvider _tempProvider; if (element.mediaItems.length > 0) { @@ -64,13 +64,16 @@ class LibraryItemsCubit extends Cubit { playlistName: element.albumName, imageProvider: _tempProvider, subTitle: "${element.mediaItems.length} Items"); - libraryItemsState.playlists.add(_playlistItem); + // libraryItemsState.playlists.add(_playlistItem); + _playlists.add(_playlistItem); // libraryItemsState.playlistNames?.add(element.albumName); // libraryItemsState.subTitles?.add("Saavan"); } - emit(libraryItemsState); - log("emitted from library ${_playlists.toString()} - ${libraryItemsState.playlists.length} - MediaPlaylists ${mediaPlaylist}", + if (_playlists.length == mediaPlaylist.length) { + emit(state.copyWith(playlists: _playlists)); + } + log("emitted from library ${_playlists.length} - MediaPlaylists ${mediaPlaylist.length}", name: "libItemsCubit"); } }