showDestructiveDialogue method Null safety

void showDestructiveDialogue(
  1. {required BuildContext context,
  2. required String title,
  3. required String message,
  4. required Future<void> onConfirm(
      )}
    )

    Shows a destructive dialogue containing a negative title and message, for confirming the execution of a destructive action. For example, deleting a message.

    One action is to 'Cancel' which closes the dialogue, doing nothing. The other action is 'Delete' which executes the destructive action onConfirm.

    Implementation

    static void showDestructiveDialogue(
        {required BuildContext context,
        required String title,
        required String message,
        required Future<void> Function() onConfirm}) {
      showDialog(
        context: context,
        builder: (BuildContext context) => AlertDialog(
          title: Text(title),
          content: Text(message),
          actions: <Widget>[
            TextButton(
              onPressed: () => Navigator.pop(context),
              child: const Text('Cancel'),
              style: ButtonStyle(
                foregroundColor: MaterialStateProperty.all(Colors.black),
              ),
            ),
            TextButton(
              onPressed: () async {
                await onConfirm();
                Navigator.pop(context);
              },
              child: const Text("Delete"),
              style: ButtonStyle(
                foregroundColor: MaterialStateProperty.all(Colors.red),
              ),
            ),
          ],
        ),
      );
    }