showCupertinoProgressDialog<T> function

Future<ProgressDialogResult<T>> showCupertinoProgressDialog<T>({
  1. required BuildContext context,
  2. required Task<T> future,
  3. WidgetBuilder? builder,
  4. Offset? anchorPoint,
  5. String? barrierLabel,
  6. bool useRootNavigator = true,
  7. Color? barrierColor,
  8. bool? requestFocus,
})

Shows a Cupertino-styled progress dialog while executing an asynchronous task.

Displays a modal progress dialog with iOS-style appearance that remains visible until future completes.

Parameters:

  • context - The build context used to show the dialog
  • future - The async task to execute while showing the progress dialog
  • builder - Optional custom widget builder for the progress dialog UI
  • useRootNavigator - Whether to show dialog above all screens, defaults to true
  • anchorPoint - Optional anchor point for the dialog position
  • barrierLabel - Semantic label used for the modal barrier
  • barrierColor - Color of the modal barrier behind the dialog
  • requestFocus - Whether the dialog should request focus when opened

Returns a ProgressDialogResult containing either the successful result value or error details if the future fails.

Example:

final result = await showCupertinoProgressDialog(
  context: context,
  future: () => myAsyncTask(),
);

switch (result) {
  case Success(value: final value):
    print('Task completed successfully: $value');
    break;
  case Failure(error: final error):
    print('Task failed: $error');
    break;
}

Implementation

Future<ProgressDialogResult<T>> showCupertinoProgressDialog<T>({
  required c.BuildContext context,
  required Task<T> future,
  c.WidgetBuilder? builder,
  c.Offset? anchorPoint,
  String? barrierLabel,
  bool useRootNavigator = true,
  c.Color? barrierColor,
  bool? requestFocus,
}) async {
  final navigator = c.Navigator.of(context, rootNavigator: useRootNavigator);

  late final c.CupertinoDialogRoute<ProgressDialogResult<T>> route;

  route = c.CupertinoDialogRoute<ProgressDialogResult<T>>(
    builder: (context) => ExactlyOnce(
      callback: () => _callback(navigator, future, route),
      child: builder?.call(context) ?? const CupertinoProgressBarDialog(),
    ),
    context: context,
    barrierDismissible: false,
    barrierLabel: barrierLabel,
    barrierColor: barrierColor,
    anchorPoint: anchorPoint,
    requestFocus: requestFocus,
  );
  final result = await navigator.push<ProgressDialogResult<T>>(route);
  return result!;
}