showFutureLoadingDialog<T> function
Displays a loading dialog which reacts to the given future
. The dialog
will be dismissed and the value will be returned when the future completes.
If an error occured, then onError
will be called and this method returns
null. Set title
and backLabel
to controll the look and feel or set
LoadingDialog.defaultTitle, LoadingDialog.defaultBackLabel and
LoadingDialog.defaultOnError to have global preferences.
Implementation
Future<LoadingDialogResult<T>> showFutureLoadingDialog<T>({
required BuildContext context,
required Future<T> Function() future,
String? title,
String? backLabel,
String Function(dynamic exception)? onError,
bool barrierDismissible = false,
}) async {
final dialog = LoadingDialog<T>(
future: future,
title: title,
backLabel: backLabel,
onError: onError,
);
final result = dialog.isCupertinoStyle
? await showCupertinoDialog<LoadingDialogResult<T>>(
barrierDismissible: barrierDismissible,
context: context,
builder: (BuildContext context) => dialog,
)
: await showDialog<LoadingDialogResult<T>>(
context: context,
barrierDismissible: barrierDismissible,
builder: (BuildContext context) => dialog,
);
return result ??
LoadingDialogResult<T>(
error: Exception('FutureDialog canceled'),
stackTrace: StackTrace.current,
);
}