showConfirmation function

void showConfirmation({
  1. BuildContext? context,
  2. required String title,
  3. required String text,
  4. required void onConfirmPressed(),
  5. String cancelButtonText = "Cancel",
  6. String confirmButtonText = "Confirm",
})

Implementation

void showConfirmation({
  BuildContext? context,
  required String title,
  required String text,
  required void Function() onConfirmPressed,
  String cancelButtonText = "Cancel",
  String confirmButtonText = "Confirm",
}) {
  if (context == null && (!state.isContextLoaded || !state.appContext.mounted)) {
    assert(false,
    "App Context was not loaded or not mounted");

    return;
  }
  if (context != null && !context.mounted) {
    assert(false,
    "Provided Context was not loaded or not mounted");

    return;
  }
  context = context?? state.appContext;

  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text(title),
        content: Text(text),
        actions: [

          TextButton(
            child: Text(cancelButtonText),
            onPressed: () {
              Navigator.of(context).pop();
            },
          ),

          TextButton(
            child: Text(confirmButtonText),
            onPressed: () async {
              Navigator.of(context).pop();
              onConfirmPressed();
            },
          ),

        ],
      );
    },
  );
}