showConfirmation method

Future<bool> showConfirmation({
  1. String? title,
  2. String? message,
  3. Map? props,
  4. BuildContext? context,
})

Builds a confirmation dialog with a given title and message.

Implementation

Future<bool> showConfirmation(
    {String? title,
    String? message,
    Map? props,
    BuildContext? context}) async {
  if (title == null && message == null) {
    return true;
  }

  final attributes = Map<String, dynamic>.from(props?["attributes"] ?? {});
  final titleText = title != null
      ? Text(properties.getText(title, "dialogTitle", attributes: attributes))
      : null;
  final content = message != null
      ? Text(properties.getText(message, "message", attributes: attributes))
      : null;
  final result = await showDialog<bool>(
      context: context ?? appContext,
      builder: (context) {
        return AlertDialog(
          title: titleText,
          content: content,
          actions: [
            TextButton(
                child: Text(properties.getText("no", "dialogButton")),
                onPressed: () => Navigator.of(context).pop(false)),
            TextButton(
                child: Text(properties.getText("yes", "dialogButton")),
                onPressed: () => Navigator.of(context).pop(true)),
          ],
        );
      });

  return result ?? false;
}