Handle library with Bloc Library
prasantco opened this issue · comments
Describe the bug
A clear and concise description of what the bug is.
First of all thank you so much @fayaz07 for published this great library.Really appreciated to you.
Now a days there is Bloc library is used for handling the state management, can you suggest us with one example where we are handle this library with Bloc Library. We need your example to support our production app.
I already had an idea to manage it with provider bloc, but that requires complete changing the core of the library, I will find a solution for it.
@visual-velocity
Can't you just create 3 states for the Bloc?
e.g. When accessing an API:
Handle it through BLoC listener:
GetAPILoading
- show progress dialog
GetAPILoaded
-hide progress dialog
-GetAPIFailed
-hide
body: BlocListener<ProfileBloc, ProfileState>( bloc: bloc, listener: (context, state) { if (state is ProfileInfoUpdateLoading) { pr.show(); } if (state is ProfileInfoUpdateFailed) { pr.hide(); SnackBarHelper.showErrorSnackBar(context, 'Update Profile Failed'); } if (state is ProfileInfoUpdateLoaded) { pr.hide(); updateUserInfo(state.user); isUpdated = true; SnackBarHelper.showSnackBar(context, 'Succesfully Updated Profile'); } },
I had already tried and it's worked.
Where will i create the object of progress_dialog is correct if I have to call an event in initState.
Inside Either InitState or BLoC listener(if (state is ProfileInfoUpdateLoading) { pr.show(); })
But i'm not able to update the content of progress dialog continuously with bloc.
@visual-velocity It is possible. I'm currently using in this way:
@override
Widget build(BuildContext context) {
_downloadDialog ??= ProgressDialog(
context,
type: ProgressDialogType.Download,
isDismissible: true,
)..style(message: 'Downloading...');
return BlocConsumer<ManageFlightDataDownloadsBloc, ManageFlightDataDownloadsState>(
builder: _buildView,
listener: (context, state) async {
if (state.isDownloadInProgress) {
await _downloadDialog.show();
_downloadDialog.update(progress: state.progress);
} else {
await _downloadDialog.hide();
}
},
);
}
But it would be better if could be used "the BLoC way"