fayaz07 / progress_dialog

A light weight library to easily manage a progress dialog with simple steps whenever you need to do it. You can easily show and hide it.

Home Page:https://fayaz07.github.io/progress_dialog/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Progress dialog is not hiding on catchError

nikhilvc opened this issue · comments

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

show me the code

I handle this issue with blow code

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

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

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();

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.

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

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();

        ...
      });
    });

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

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

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