Relative Content

Tag Archive for flutterbloc

How to use bloc with show Dialog flutter

currently, I have an IconButton in the appbar of ListScreen. But when I click on it, it show up an error that do not recognize bloc in widget tree ? what can i do.

I’m trying to manage state using Bloc. but i keep getting this error “This expression has a type of ‘void’ so its value can’t be used.”

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 […]

In flutter BLoC, how to optimize the creation of repeated, multiple dart files?

I am working on a flutter project. I have 5 basic components where I have a list of items to display, add item screen and delete item screen. So in all of the modules I am gonna have same states & events. I want to know whether it is critical to maintain a dedicated state.dart file & event.dart file for each of the components ?

Unable to set text in Flutter

I am using Bloc pattern and I am getting successful response/data when printed but when I am setting the response on the Text widget its giving me error.