Skip to content

Commit

Permalink
library repeated list fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Feb 3, 2024
1 parent afa73f3 commit 22bf491
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions lib/blocs/library/cubit/library_items_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ class LibraryItemsCubit extends Cubit<LibraryItemsState> {
}

Future<void> getAndEmitPlaylists() async {
List<PlaylistItemProperties> _playlists = List.empty(growable: true);
libraryItemsState =
LibraryItemsState(playlists: List.empty(growable: true));

mediaPlaylist = await mediaDBCubit.getListOfPlaylists2();

List<String> _playlists = List.empty(growable: true);
// List<String> _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) {
Expand All @@ -64,13 +64,16 @@ class LibraryItemsCubit extends Cubit<LibraryItemsState> {
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");
}
}
Expand Down

0 comments on commit 22bf491

Please sign in to comment.