Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Handle library with Bloc Library #65

Open
prasantco opened this issue May 23, 2020 · 6 comments
Open

Handle library with Bloc Library #65

prasantco opened this issue May 23, 2020 · 6 comments

Comments

@prasantco
Copy link

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.

@prasantco
Copy link
Author

prasantco commented May 25, 2020

@fayaz07 have you looked or considered my issue?

@fayaz07
Copy link
Owner

fayaz07 commented May 26, 2020

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.

@prasantco
Copy link
Author

prasantco commented May 26, 2020 via email

@rhyscoronado
Copy link

@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'); } },

@prasantco
Copy link
Author

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.

@fernando-s97
Copy link

fernando-s97 commented Aug 11, 2020

@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"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants