future<T> static method

Future future<T>(
  1. BuildContext context, {
  2. required Future future,
  3. OnProgressError? onProgressError,
  4. OnProgressFinish? onProgressFinish,
  5. OnProgressCancel? onProgressCancel,
  6. Color? backgroundColor,
  7. double? blur,
  8. Function? onDismiss,
  9. bool? dismissable,
  10. Widget? loadingWidget,
  11. DialogTransitionType? dialogTransitionType,
  12. Duration? transitionDuration,
  13. bool useSafeArea = true,
})

future function let you show ProgressDialog until future (param) reach the end of its action

Implementation

static Future future<T>(
  BuildContext context, {
  required Future future,
  OnProgressError? onProgressError,
  OnProgressFinish? onProgressFinish,
  OnProgressCancel? onProgressCancel,
  Color? backgroundColor,
  double? blur,
  Function? onDismiss,
  bool? dismissable,
  Widget? loadingWidget,
  DialogTransitionType? dialogTransitionType,
  Duration? transitionDuration,
  bool useSafeArea = true,
}) async {
  CustomProgressDialog pDialog = CustomProgressDialog(
    context,
    loadingWidget: loadingWidget,
    dismissable: dismissable,
    backgroundColor: backgroundColor,
    blur: blur,
    onDismiss: onDismiss,
    onCancel: onProgressCancel != null ? onProgressCancel : null,
    dialogTransitionType: dialogTransitionType,
    transitionDuration: transitionDuration,
  );

  pDialog.show(useSafeArea: useSafeArea);

  var output;
  try {
    await future.then((data) {
      if (onProgressFinish != null)
        onProgressFinish = onProgressFinish!(data);
      output = data;
    }).catchError((error) {
      if (onProgressError != null) onProgressError = onProgressError!(error);
    });
  } catch (e) {}
  pDialog.dismiss();

  return output;
}