launchConfirmDialog function

Future<void> launchConfirmDialog(
  1. BuildContext context,
  2. {required Widget message,
  3. Icon? icon,
  4. bool showTitle = true,
  5. String title = "Are you sure?",
  6. bool showOkLabel = true,
  7. String okLabel = "Yes",
  8. String denyLabel = "No",
  9. bool callAfter = false,
  10. required void onConfirm(
      ),
    1. void onDeny(
        )?}
      )

      generic confirmation dialog

      Implementation

      @pragma("vm:prefer-inline")
      Future<void> launchConfirmDialog(BuildContext context,
          {required Widget message,
          Icon? icon,
          bool showTitle = true,
          String title = "Are you sure?",
          bool showOkLabel = true,
          String okLabel = "Yes",
          String denyLabel = "No",
          bool callAfter = false,
          required void Function() onConfirm,
          void Function()? onDeny}) async {
        Debug().info(
            "Launched a CONFIRM_DIALOG with ${message.hashCode}"); // we use the provided context
        await showDialog(
            context: context,
            builder: (BuildContext context) => AlertDialog(
                    icon: icon ?? const Icon(Icons.warning_amber_rounded),
                    title: showTitle ? Text(title) : null,
                    content: message,
                    actions: <Widget>[
                      if (showOkLabel)
                        TextButton.icon(
                          icon: const Icon(Icons.check_rounded),
                          label: Text(okLabel,
                              style: const TextStyle(
                                  fontWeight: FontWeight.w700)),
                          onPressed: () {
                            if (callAfter) {
                              Navigator.of(context).pop();
                              onConfirm.call();
                              Debug().info(
                                  "CONFIRM_DIALOG [${message.hashCode}] ended with CONFIRM");
                            } else {
                              onConfirm.call();
                              Navigator.of(context).pop();
                              Debug().info(
                                  "CONFIRM_DIALOG [${message.hashCode}] ended with CONFIRM");
                            }
                          },
                        ),
                      TextButton.icon(
                        icon: const Icon(Icons.not_interested_rounded),
                        label: Text(denyLabel,
                            style: const TextStyle(
                                fontWeight: FontWeight.w700)),
                        onPressed: () {
                          onDeny?.call();
                          Navigator.of(context).pop();
                          Debug().info(
                              "CONFIRM_DIALOG [${message.hashCode}] ended with DENY");
                        },
                      )
                    ]));
      }