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

Progress dialog is not hiding on catchError #36

Closed
nikhilvc opened this issue Dec 2, 2019 · 8 comments
Closed

Progress dialog is not hiding on catchError #36

nikhilvc opened this issue Dec 2, 2019 · 8 comments

Comments

@nikhilvc
Copy link

nikhilvc commented Dec 2, 2019

i want to show progress dialog on before of API call .while calling API if there is any error occurred i wants to hide the dialog on CatchError function

@fayaz07
Copy link
Owner

fayaz07 commented Dec 3, 2019

show me the code

@nikhilvc
Copy link
Author

nikhilvc commented Dec 3, 2019

I handle this issue with blow code

Future.delayed(Duration(seconds: 3)).then((onValue) {
if (pr.isShowing())
pr.hide().whenComplete(() {
showToast("error");
});
});

@openwrd
Copy link

openwrd commented Dec 10, 2019

pr.show();
pr.hide(); //not working

@nithish-knetworks
Copy link

Not able to close the Dialog.
Source Code:
ProgressDialog progressDialog = ProgressDialog(context,
type: ProgressDialogType.Normal,isDismissible: true);
progressDialog.style(
message: 'Saving...',
backgroundColor: Colors.white,
progressWidget: CircularProgressIndicator(),
elevation: 10.0,
insetAnimCurve: Curves.easeInOut,
progress: 0.0,
borderRadius: 10.0,
maxProgress: 100.0,
progressTextStyle: TextStyle(
color: Colors.black, fontSize: 13.0, fontWeight: FontWeight.w400),
messageTextStyle: TextStyle(
color: Colors.black, fontSize: 19.0, fontWeight: FontWeight.w600));
progressDialog.show();
//Service layer Call(Async call)
progressDialog.hide();

@Bahaaib
Copy link

Bahaaib commented Feb 4, 2020

Hi,
I faced the same issue specifically when any exception has been thrown, i couldn't dismiss the progress dialog in any possible way.
The Solution is:
inside your catch add Navigator.of(context).pop(); instead of progressDialog.dismiss().

That works because basically flutter has 2 default routes. The main route which by default renders the Scaffolds and gives them control over the screen. The other is the Modal route which renders over the main route. When a main route tries to render some dialog, it passes the current context to the dialog to take control over the screen. when you dismiss the dialog, you return the context back to the main route. The thing that we've done here.

@AldiSatrioAji
Copy link

@Bahaaib Been stuck for an hour and finally it's working for me! Thanks

@rochadaniel
Copy link

After the #41 this code worked for me (handle .show() asynchronously):

ProgressDialog myDialog = ProgressDialog(context, type: ProgressDialogType.Normal);

myDialog.show().then((onValue) {
      myFuture().then((myResult) {
        myDialog.hide();
        
        ...
      }).catchError((onError) {
        myDialog.hide();

        ...
      });
    });

@fayaz07
Copy link
Owner

fayaz07 commented Apr 11, 2020

Please use the following code for showing or hiding the progress dialog

/// for showing
await pr.show();

/// for hiding
await pr.hide();

@fayaz07 fayaz07 closed this as completed Apr 11, 2020
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

7 participants