confirm function

Future confirm([
  1. String message = ""
])

Implementation

Future<dynamic> confirm([String message = ""]) async {
  Completer c = Completer();
  Dialog confirmDialog = Dialog("Confirm", [Text(message)], true);

  confirmDialog
    ..showDialog()
    ..okButton.focus()
    ..dialogBackdrop.onClick.first.then((_) {
      c.complete(false);
      confirmDialog.closeDialog();
    });

  querySelectorAll(".modal button").forEach((Element buttons) {
    buttons.onClick.first.then((e) {
      if (e.target == confirmDialog.okButton) {
        c.complete(true);
      } else {
        c.complete(false);
      }
      confirmDialog.closeDialog();
    });
    buttons.onKeyDown.listen((e) {
      if (e.keyCode == KeyCode.ESC) {
        c.complete(false);
        confirmDialog.closeDialog();
      }
    });
  });

  return c.future;
}