showChoicesButtonDialog<T> function

Future<T> showChoicesButtonDialog<T>(
  1. BuildContext context,
  2. {Widget title,
  3. Widget content,
  4. @required List<DialogChoice<T>> choices,
  5. Widget cancelWidget,
  6. bool barrierDismissible = false,
  7. Color barrierColor,
  8. bool useSafeArea = true,
  9. bool useRootNavigator = true,
  10. RouteSettings routeSettings}
)

Displays a dialog with the choices informed in the parameter choices similar to a ListTile.

This dialog will be closed the moment you click on one of the choices listed on the screen, or when the Cancel button is clicked.

Example of using the dialog:

String result = await showChoicesButtonDialog<String>(context,
    title: Text('Select user'),
    choices: [
        DialogChoice(
            icon: Icon(Icons.person),
            title: Text('Ricardo Crescenti'),
            subtitle: Text('ricardo.crescenti@gmail.com'),
            value: 'ricardo.crescenti'),
        DialogChoice(
            icon: Icon(Icons.person),
            title: Text('Ana Luiza Crescenti'),
            subtitle: Text('analuiza.crescenti@gmail.com'),
            value: 'analuiza.crescenti'),
        DialogChoice(
            icon: Icon(Icons.person),
            title: Text('Luis Otávio Crescenti'),
            subtitle: Text('luisotavio.crescenti@gmail.com'),
            value: 'luisotavio.crescenti'),
        DialogChoice(
            icon: Icon(Icons.add),
            title: Text('Add new account'),
            value: ''),
    ]);

if (result != null) {
    showBasicDialog(context, title: Text('Selected user'), content: Text(result));
}

Implementation

Future<T> showChoicesButtonDialog<T>(BuildContext context,
    {Widget title,
    Widget content,
    @required List<DialogChoice<T>> choices,
    Widget cancelWidget,
    bool barrierDismissible = false,
    Color barrierColor,
    bool useSafeArea = true,
    bool useRootNavigator = true,
    RouteSettings routeSettings}) async {
  List<T> result = await _showChoicesDialog<T>(context,
      title: title,
      content: content,
      choiceType: DialogChoicesType.button,
      choices: choices,
      cancelWidget: cancelWidget,
      barrierDismissible: barrierDismissible,
      barrierColor: barrierColor,
      useSafeArea: useSafeArea,
      useRootNavigator: useRootNavigator,
      routeSettings: routeSettings);

  return (result != null && result.isNotEmpty ? result[0] : null);
}