showBasicDialog<T> function

Future<T> showBasicDialog<T>(
  1. BuildContext context,
  2. {Widget title,
  3. Widget content,
  4. List<DialogAction<T>> actions,
  5. bool barrierDismissible = false,
  6. Color barrierColor,
  7. bool useSafeArea = true,
  8. bool useRootNavigator = true,
  9. RouteSettings routeSettings}
)

Displays a basic dialog with title and simple content, with the possibility to add customizable action buttons.

You can show the dialog only with the title, and optionally you can enter a content with details of the dialog.

It is also possible to add as many action buttons as needed, and each button will have its action and return.

Below is an example of a dialog with title, content and two buttons to return true or false.

final result = await showBasicDialog<bool>(context,
    title: Text('Basic dialog example'),
    content: Text('Content of the dialogue, here you can explain in detail the reason for the dialogue'),
    actions: [
        DialogAction(title: Text('NO'), value: (context) => false),
        DialogAction(title: Text('YES'), value: (context) => true)
    ]
);

Implementation

Future<T> showBasicDialog<T>(BuildContext context,
    {Widget title,
    Widget content,
    List<DialogAction<T>> actions,
    bool barrierDismissible = false,
    Color barrierColor,
    bool useSafeArea = true,
    bool useRootNavigator = true,
    RouteSettings routeSettings}) async {
  assert(title != null || content != null);

  return showDialog<T>(
      context: context,
      builder: (context) {
        return WillPopScope(
            onWillPop: () => Future.value(barrierDismissible),
            child: AlertDialog(
              title: title,
              content: content,
              actions: (actions ??
                      [
                        DialogAction<T>(
                          title: Text(StandardDialogsLocalizations.of(
                              context)[DialogResult.ok]),
                          action: null,
                        )
                      ])
                  .map<TextButton>((e) => TextButton(
                      onPressed: () => e.performClick(context), child: e.title))
                  .toList(),
            ));
      },
      barrierDismissible: barrierDismissible,
      barrierColor: barrierColor,
      useSafeArea: useSafeArea,
      useRootNavigator: useRootNavigator,
      routeSettings: routeSettings);
}