confirmDialog function

Future confirmDialog({
  1. String title = 'Confirm',
  2. String content = 'Are you sure?',
  3. Function? confirm,
  4. Function? cancel,
  5. String confirmLabel = 'Yes',
  6. String cancelLabel = 'No',
})

Implementation

Future<dynamic> confirmDialog({
  String title = 'Confirm',
  String content = 'Are you sure?',
  Function? confirm,
  Function? cancel,
  String confirmLabel = 'Yes',
  String cancelLabel = 'No',
}) async {
  void close(cback, result) {
    Get.back(result: result);
    if (cback != null) cback();
  }

  return _createDialog(
    title: title,
    content: content,
    actions: [
      Button(
        label: cancelLabel,
        backgroundColor: Colors.red,
        color: Colors.white,
        borderRadius: 10,
        borderColor: Colors.black,
        onClick: (_) => close(cancel, false),
      ),
      Button(
        label: confirmLabel,
        backgroundColor: Colors.green,
        color: Colors.white,
        borderRadius: 10,
        borderColor: Colors.black,
        onClick: (_) => close(confirm, true),
      ),
    ],
  );
}