ask<T> function

Future<T> ask<T>(
  1. {String title = '',
  2. String message = '',
  3. List<AskButton<T>> buttons = const [],
  4. @required BuildContext context,
  5. dynamic defaultValue}
)

Open a dialog, show the message and buttons, and return a value corresponding to the button's value.

Implementation

Future<T> ask<T>(
    {String title = '',
    String message = '',
    List<AskButton<T>> buttons = const [],
    @required BuildContext context,
    defaultValue}) async {
  return await showDialog(
        context: context,
        builder: (context) => AlertDialog(
          title: title == '' ? null : Text(title),
          content: Text(message),
          actions: buttons
              .map((button) => _getButton(context, button, () {
                    Navigator.pop(context, button.value);
                  }))
              .toList(),
        ),
      ) ??
      defaultValue;
}