Questions tagged [flutter-bloc]

For questions relating to the "flutter_bloc" package for the Flutter framework. Use this tag in combination with the general [flutter] tag. If your question applies to Flutter more generally, use the [flutter] tag only.

This tag should be used for any questions regarding the flutter_bloc package for the Flutter framework.

flutter_bloc is a package implementing the BloC pattern for Flutter, specifically the BlocProvider and BlocBuilder classes.

To get started, you can read through the README document on GitHub.

932 questions
3
votes
2 answers

Why putting bloc providers in a separate file/class throws an error?

I have this code: MultiBlocProvider( providers: [ BlocProvider( create: (context) => CubitExample(), ), ], child: MaterialApp( home: Home(), ), ); It's working fine, I have many cubits/blocs so I decided to move the…
Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
3
votes
1 answer

One state with a property called status or different states in Flutter Bloc, which is more preferrable?

I was just wondering is there a difference between having different states vs having one state that has a property status to denote the current status of the state (e.g whether it's success or error)? Is there a best practice for declaration of…
ejandra
  • 336
  • 2
  • 4
  • 15
3
votes
3 answers

Flutter BLoC - Bloc vs Cubit event driven state management advantages

What are the actual advantage(s) of Bloc over Cubit? In addition to traceability (which you can also achieve with appropriate logging in Cubit), and advanced event transformations (I can't think of any "advanced" event transformations that Cubit…
3
votes
1 answer

How to handle errors with BLoC?

I see people use onError just for debugging. I thought I could use it to emit new states like emit(ErrorState(message: "An error")). But with the new versions of the bloc package, we should use emitters provided to the handlers and shouldn't use the…
kozhioyrin
  • 400
  • 4
  • 15
3
votes
1 answer

Flutter bloc - emit was called after an event handler completed normally

I have this code in user_bloc.dart: UserBloc(this._userRepository, UserState userState) : super(userState) { on(_onRegisterUser); } void _onRegisterUser(RegisterUser event, Emitter emit) async { …
Rony Tesler
  • 1,207
  • 15
  • 25
3
votes
2 answers

When to use .add() and when to use emit() in Flutter Bloc?

I am new to Bloc in flutter, any one can please explain when should I use add() and when to use emit in Blocs?
3
votes
2 answers

Unhandled Exception: Invalid argument (computation): The type parameter is not nullable: null

Trying to run the following Flutter code in android Studio Link to code on github https://github.com/cyeh1234/bloc_bug.git Got the following error: https://www.mitrais.com/news-updates/getting-started-with-flutter-bloc-pattern/ Correct output
chuck
  • 71
  • 1
  • 5
3
votes
1 answer

flutter_bloc (emit was called after an event handler completed normally

So, I was working with Django rest framework creating my APIs and all. And i wanted to check if I can get the response from the backend. So, I was able to get the response. But I saw some issues on the debug console. Please help me figure out the…
Biplab Dutta
  • 444
  • 3
  • 12
3
votes
2 answers

How to manage different States in the same Bloc? Flutter

I am trying to handle 3 different states in my app, in the initState of my home, I call the event "OnInitial" pretending to be a method that fetches data from the local DB. As you can see in the method on I am setting "6" to the variable "number"…
Dubbain
  • 73
  • 1
  • 8
3
votes
1 answer

Flutter BLoC event race condition

Let's assume we have an app where user has a calendar where he can select a date for which he wants to get list of events. When user selects the date, we add an event CalendarSelectedDateChanged(DateTime). Bloc component fetches data from API each…
RMK
  • 1,897
  • 1
  • 10
  • 17
3
votes
3 answers

TextField and BLoC - value not updated or keyboard dismissed

I want to use a TextField in combination with BLoC package in Flutter. The aim is to keep the content of the TextField in sync with the respective property of the BLoC. Because BLoC is based on a BlocBuilder widget that basically subscribes to a…
Schnodderbalken
  • 3,257
  • 4
  • 34
  • 60
3
votes
2 answers

how to implement debouncer for events with 'onEvent'?

transformEvents method will be removed in bloc version 8, and we should use onEvent method instead of, how can we implement debounce for events with onEvent? @override Stream> transformEvents( …
Hamed
  • 5,867
  • 4
  • 32
  • 56
3
votes
1 answer

How to register a class with generic type param using injectable?

I have a bloc, that I want to register for DI: @injectable class ViewBloc extends Bloc { } As you can see the ViewBloc takes a generic type param T. The problem is that when the injectable register the dependency, it's…
Nebex Elias
  • 252
  • 1
  • 3
  • 14
3
votes
2 answers

Flutter could not find the correct Provider above BlocConsumer Widget

I'm using Flutter Bloc for a project. This is the structure: MultiBlocProvider( providers: [ BlocProvider( create: (context) { return BlocA() ..add(FetchEvent()); …
Nithin Sai
  • 840
  • 1
  • 10
  • 23
3
votes
1 answer

Issue With Nested BlocBuilder() Calls

My Flutter app has multiple BloCs (via the bloc and flutter_bloc packages) which has caused some technical difficulties that I solved using a workaround, but I was wondering if there was a better solution out there. I am using BlocBuilder() when…
Jose
  • 311
  • 2
  • 9