The following happens to me ... there comes a time in my APP that much more work to create the BLOC itself than to focus on the main thing.
For example, on a screen I have a widget that gets the current weather from an API (I have a BLOC for that).
Under that widget (list view), I have another one that gets the next 5 days. Another endpoint, another BLOC ...
In a screen I already have 2 BLOC, and could have more if I have to consume some other logic.
This with pure BLOC, it would be one more sink in the stream and that's it.
But with the library, it takes you much longer to create the BLOC ... do you agree with this? that at certain times, are more lines to be written and files?
Excuse my speech, I'm from Argentina
Hi @ignaciolopez12 馃憢
Thanks for opening an issue!
It's up to you how you want to structure your application in terms of blocs but in general I would recommend having one bloc per use case (not necessarily one bloc per API request).
For example if you have a dashboard in your application that requests data from multiple APIs I would recommend having a single DashboardBloc with states like:
class DashboardLoadInProgress extends DashboardState {}
class DashboardLoadFailure extends DashboardState {}
class DashboardLoadSuccess extends DashboardState {
DashboardLoadSuccess({@required this.dataA, @required this.dataB, @required this.dataC});
final DataA dataA;
final DataB dataB;
final DataC dataC;
}
Rather than have DataABloc, DataBBloc, and DataCBloc. This should simplify both your bloc and UI layers. In addition, if you aren't already I highly recommend using the Bloc VSCode extension or Bloc IntelliJ plugin to help you quickly and consistently generate your blocs 馃憤
Hope that helps 馃槃
Hi @ignaciolopez12
Thanks for opening an issue!It's up to you how you want to structure your application in terms of blocs but in general I would recommend having one bloc per use case (not necessarily one bloc per API request).
For example if you have a dashboard in your application that requests data from multiple APIs I would recommend having a single
DashboardBlocwith states like:class DashboardLoadInProgress extends DashboardState {} class DashboardLoadFailure extends DashboardState {} class DashboardLoadSuccess extends DashboardState { DashboardLoadSuccess({@required this.dataA, @required this.dataB, @required this.dataC}); final DataA dataA; final DataB dataB; final DataC dataC; }Rather than have
DataABloc,DataBBloc, andDataCBloc. This should simplify both your bloc layer as well as your UI layer. In addition, if you aren't already I highly recommend using the Bloc VSCode extension or Bloc IntelliJ plugin to help you quickly and consistently generate your blocsHope that helps
Great! It hadn't occurred to me that way. Also do some research on their GitHub examples and I didn't see something like you mentioned.
I thank you and I will try it
Most helpful comment
Great! It hadn't occurred to me that way. Also do some research on their GitHub examples and I didn't see something like you mentioned.
I thank you and I will try it