showCupertinoProgressDialog<T> function
Future<ProgressDialogResult<T> >
showCupertinoProgressDialog<T>({
- required BuildContext context,
- required Task<
T> future, - WidgetBuilder? builder,
- Offset? anchorPoint,
- String? barrierLabel,
- Color? barrierColor,
- 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 dialogfuture- The async task to execute while showing the progress dialogbuilder- Optional custom widget builder for the progress dialog UIuseRootNavigator- Whether to show dialog above all screens, defaults to trueanchorPoint- Optional anchor point for the dialog positionbarrierLabel- Semantic label used for the modal barrierbarrierColor- Color of the modal barrier behind the dialogrequestFocus- Whether the dialog should request focus when opened
Returns a ProgressDialogResult: Success with the value, Failure with the
error details if the future fails, or Cancelled if the dialog is dismissed
before the task delivers a result — for example by the Android back button, or
by a custom builder that calls Navigator.pop. The task itself is not
interrupted in that case; it runs to completion and its result is discarded.
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;
case Cancelled():
print('Dialog dismissed before the task finished');
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;
final outcome = _Outcome<T>();
route = c.CupertinoDialogRoute<ProgressDialogResult<T>>(
builder: (context) => ExactlyOnce(
callback: () => _callback(navigator, future, route, outcome.settle),
onDispose: () => outcome.settle(Cancelled<T>()),
child: builder?.call(context) ?? const CupertinoProgressBarDialog(),
),
context: context,
barrierDismissible: false,
barrierLabel: barrierLabel,
barrierColor: barrierColor,
anchorPoint: anchorPoint,
requestFocus: requestFocus,
);
return outcome.track(navigator, route);
}