showProgressDialog<T> function
Future<ProgressDialogResult<T> >
showProgressDialog<T>({
- required BuildContext context,
- required Task<
T> future, - WidgetBuilder? builder,
- Offset? anchorPoint,
- String? barrierLabel,
- bool? requestFocus,
- TraversalEdgeBehavior? traversalEdgeBehavior,
- Color? barrierColor,
- bool useSafeArea = true,
- bool fullscreenDialog = false,
- AnimationStyle? animationStyle,
Shows a progress dialog while executing a Future task.
This function displays a modal progress dialog that remains visible until the provided
future completes. The dialog can be customized using the builder parameter.
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 barrierrequestFocus- Whether the dialog should request focus when openedtraversalEdgeBehavior- Determines dialog edge behavior when using keyboard traversalbarrierColor- Color of the modal barrier, defaults to black54useSafeArea- Whether to respect system UI safe areas, defaults to truefullscreenDialog- Whether this dialog is a fullscreen dialoganimationStyle- Style of the dialog animation
Returns a ProgressDialogResult containing either the successful result value or error details if the future fails.
Example:
final result = await showProgressDialog(
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>> showProgressDialog<T>({
required m.BuildContext context,
required Task<T> future,
m.WidgetBuilder? builder,
bool useRootNavigator = true,
m.Offset? anchorPoint,
String? barrierLabel,
bool? requestFocus,
m.TraversalEdgeBehavior? traversalEdgeBehavior,
m.Color? barrierColor,
bool useSafeArea = true,
bool fullscreenDialog = false,
m.AnimationStyle? animationStyle,
}) async {
final themes = m.InheritedTheme.capture(
from: context,
to: m.Navigator.of(context, rootNavigator: useRootNavigator).context,
);
late final m.Route<ProgressDialogResult<T>> route;
route = m.DialogRoute<ProgressDialogResult<T>>(
context: context,
builder: (context) => ExactlyOnce(
callback: () => _callback(context, future, route),
child: builder?.call(context) ?? const ProgressBarDialog(),
),
barrierColor: barrierColor ??
m.DialogTheme.of(context).barrierColor ??
m.Theme.of(context).dialogTheme.barrierColor ??
m.Colors.black54,
barrierDismissible: false,
barrierLabel: barrierLabel,
useSafeArea: useSafeArea,
themes: themes,
anchorPoint: anchorPoint,
traversalEdgeBehavior:
traversalEdgeBehavior ?? m.TraversalEdgeBehavior.closedLoop,
requestFocus: requestFocus,
animationStyle: animationStyle,
fullscreenDialog: fullscreenDialog,
);
final result = await m.Navigator.of(context, rootNavigator: useRootNavigator)
.push<ProgressDialogResult<T>>(route);
return result!;
}