class FavouriteBloc extends Bloc<FavouriteEvent, FavouriteState> {
FavouriteBloc() : super(FavouriteInitial()) {
on<AddToFavorites>((event, emit) {
List<HostelModel> hostelList = [];
emit(FavouriteUpdated(hostelList.add(event.hostel)));
});
on<RemoveFromFavorites>((event, emit) {});
}
}
sealed class FavouriteEvent {}
class AddToFavorites extends FavouriteEvent {
final HostelModel hostel;
AddToFavorites({required this.hostel});
}
class RemoveFromFavorites extends FavouriteEvent {
final HostelModel hostel;
RemoveFromFavorites({required this.hostel});
}
sealed class FavouriteState {}
final class FavouriteInitial extends FavouriteState {}
final class FavouriteUpdated extends FavouriteState {
List<HostelModel> hostelList;
FavouriteUpdated(this.hostelList);
}
I want to add this model data to the list using bloc. and later on use that list to populate a screen. im getting this error on the .add() method in the emit function. “This expression has a type of ‘void’ so its value can’t be used”