showAwaitDialog<T> function

Future<T> showAwaitDialog<T>(
  1. BuildContext context,
  2. {@required Widget message,
  3. Future<T> function(
    1. BuildContext context,
    2. dynamic updateMessage(
      1. Widget message
  4. Color barrierColor,
  5. bool useSafeArea = true,
  6. bool useRootNavigator = true,
  7. RouteSettings routeSettings}

Displays a dialog with a CircularProgressIndicator while a process is running.

To inform the process that will be executed, use the parameter function, this parameter must receive a function, which can return a value with the result function.

To inform the user what is being executed, you can use the parameter message, it can be updated as necessary during the execution of the function method that is passed as a parameter in the execution of the function.

Below is an example of how to show a dialog and wait for the process to be completed.

final result = await showAwaitDialog<bool>(context,
    message: Text('Creating user'),
    function: (context, updateMessage) async {

    await Future.delayed(Duration(seconds: 2));
    updateMessage(Text('Creating permissions'));
    await Future.delayed(Duration(seconds: 2));

    return true;


Future<T> showAwaitDialog<T>(BuildContext context,
    {@required Widget message,
    Future<T> Function(
            BuildContext context, Function(Widget message) updateMessage)
    Color barrierColor,
    bool useSafeArea = true,
    bool useRootNavigator = true,
    RouteSettings routeSettings}) {
  return showDialog<T>(
      context: context,
      builder: (context) {
        return WillPopScope(
            onWillPop: () => Future.value(false),
            child: AwaitDialog<T>(message, function));
      barrierDismissible: false,
      barrierColor: barrierColor,
      useSafeArea: useSafeArea,
      useRootNavigator: useRootNavigator,
      routeSettings: routeSettings);