showOkDialog function

Future<int?> showOkDialog(
  1. BuildContext context, {
  2. required String title,
  3. required String message,
  4. TextStyle? titleStyle,
  5. String cancelLabel = '取消',
  6. String okLabel = "确认",
})

Implementation

Future<int?> showOkDialog(
  BuildContext context, {
  required String title,
  required String message,
  TextStyle? titleStyle,
  String cancelLabel = '取消',
  String okLabel = "确认",
}) async {
  return await showCupertinoDialog<int>(
    context: context,
    builder: (_) {
      return CupertinoAlertDialog(
        title: Text(title, style: titleStyle),
        content: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(message),
        ),
        actions: [
          CupertinoDialogAction(
            onPressed: () => Navigator.pop(context, -1),
            child: Text(cancelLabel),
          ),
          CupertinoDialogAction(
            isDestructiveAction: true,
            onPressed: () => Navigator.pop(context, 1),
            child: Text(okLabel),
          )
        ],
      );
    },
  );
}