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

PD not getting dismissed some times #80

Closed
Vinayak27Mobility opened this issue Aug 15, 2020 · 5 comments
Closed

PD not getting dismissed some times #80

Vinayak27Mobility opened this issue Aug 15, 2020 · 5 comments

Comments

@Vinayak27Mobility
Copy link

Describe the bug
When dealing with Asuncións method, showing PD with Util class across app.

To Reproduce
Calling update record async Firestore method and showing Updating PD and post method calling Util.dismissProgressBar(). Please refer the code:

Util Class code :
Code :
static showProgressBar(BuildContext context, String message) async {
if(pDialog == null) {
pDialog = ProgressDialog(context,
type: ProgressDialogType.Normal,
isDismissible: false,
showLogs: true);
}
pDialog.style(message: message);
await pDialog.show();
}

static Future dismissProgressBar() async {
if (pDialog != null && pDialog.isShowing()) {
return pDialog.hide();
}
}

Calling Class Code:

try {
NetworkManager().updateChild(updatedChild).then((value) {
if (_profileImageStatus == AppConstants.profileImageUpdated) {
uploadFile(updatedChild).then((value) {
Util.dismissProgressBar().then((value) {
if (this.mounted) this.setState(() {});
});
});
} else {
//loggedUser = value;
Util.dismissProgressBar().then((value) {
if (this.mounted) this.setState(() {});
});
}
});
} catch (e) {
Fimber.e(e.toString());
}

Expected behavior
PD should get dismissed every time post method complete

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):
Flutter 1.20

Smartphone (please complete the following information):
Simulator Nexus 6P

Additional context

@rasyeda
Copy link

rasyeda commented Aug 20, 2020

It's because the pDialog is trying to hide itself when the dialog is not shown completely.
The isShowing flag is set after 200ms (the default transitionDuration of the progress_dialog).

Some workaround you can wait to 200ms when the dialog failed to hide itself.

static Future dismissProgressBar() async {

if (dialog != null) {
    bool isHidden = await dialog.hide();
    if (!isHidden) {
      Future.delayed(Duration(milliseconds: 200), (){
        dialog.hide();
      });
    }
}

@fayaz07
Copy link
Owner

fayaz07 commented Aug 20, 2020

please use await

@Vinayak27Mobility
Copy link
Author

Thank you smooch @fayaz07 and @rasyeda for help! It resolved referring to comments.

@fayaz07 fayaz07 closed this as completed Aug 23, 2020
@fernando-s97
Copy link

fernando-s97 commented Aug 26, 2020

Hi!

I'm having the same issue, but I'm using the await keyword.

await state.progress.fold<Future>(
      () => _downloadDialog.hide(),
      (progress) => _downloadDialog
          .show()
          .then((_) => _downloadDialog.update(progress: progress)),
    );
log('showing: ${_downloadDialog.isShowing()}');

The log is printing showing: false even though the dialog is being shown. Any idea?

OBS: The code above is being called in a BLoC listener (which is called multiple times).

@ethras
Copy link

ethras commented Sep 17, 2020

Same issue here on Android

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

5 participants