that would manage
is downloadable, downloaded, isremoveable, deleteable, etc
Great! Bloc is a good choice for state management and works well under such cases.
You may create a bloc for your Playlist called PlaylistBloc that fetches the required details for each playlist. Separately, create a UserBloc that maintains all the active details for the current user including their playlist IDs.
To decide if the playlist should be removable or followable, you may create a method in PlaylistBloc that listens to the current state of UserBloc. Here is a simple example:
class PlaylistBloc extends Bloc<PlaylistEvent, PlaylistState> {
final UserBloc userBloc;
late StreamSubscription userSubscription;
PlaylistBloc({required this.userBloc}) : super() {
userSubscription = userBloc.stream.listen((state) {
if (state is UserDetailsLoadSuccess) {
add(CheckPlaylistRemovabilityAndFollowability(state.playlistIds)); // event to check removability and followability
}
});
}
@override
Stream<PlaylistState> mapEventToState(PlaylistEvent event) async* {
if (event is CheckPlaylistRemovabilityAndFollowability) {
final isRemovable = event.playlistIds.contains(playlist.id); // assuming playlist is the current playlist object
final isFollowable = !event.playlistIds.contains(playlist.id);
// set the isRemovable and isFollowable properties
// yield new state with the updated playlist object
}
}
@override
Future<void> close() {
userSubscription.cancel();
return super.close();
}
}
Please note that you'd need to adapt this code to fit into your application, as I just provide a simple example.
The key here is listening to the userBloc's state from within the playlistBloc so that each time the user's playlistIds change, the playlistBloc is notified and updates the isRemovable and isFollowable properties accordingly.
that would manage is downloadable, downloaded, isremoveable, deleteable, etc
Great! Bloc is a good choice for state management and works well under such cases.
You may create a bloc for your
Playlist
calledPlaylistBloc
that fetches the required details for each playlist. Separately, create aUserBloc
that maintains all the active details for the current user including their playlist IDs.To decide if the playlist should be removable or followable, you may create a method in
PlaylistBloc
that listens to the current state ofUserBloc
. Here is a simple example:Please note that you'd need to adapt this code to fit into your application, as I just provide a simple example.
The key here is listening to the userBloc's state from within the playlistBloc so that each time the user's playlistIds change, the playlistBloc is notified and updates the isRemovable and isFollowable properties accordingly.