confirm_box.dart 976 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:vitalapp/components/alert_dialog.dart';
  4. class ConfirmBox {
  5. static Future<bool> show({
  6. String? title,
  7. required String content,
  8. VoidCallback? onConfirm,
  9. VoidCallback? onCancel,
  10. double? width,
  11. }) async {
  12. final result = await Get.dialog(
  13. VAlertDialog(
  14. title: title ?? "提示",
  15. width: width ?? 320,
  16. content: Container(
  17. height: 32,
  18. padding: const EdgeInsets.symmetric(horizontal: 24),
  19. alignment: Alignment.center,
  20. child: Text(content, style: TextStyle(fontSize: 20)),
  21. ),
  22. onConfirm: () async {
  23. onConfirm?.call();
  24. Get.back(result: true);
  25. },
  26. onCanceled: () {
  27. onCancel?.call();
  28. return false;
  29. },
  30. ),
  31. barrierDismissible: false,
  32. barrierColor: Colors.black.withOpacity(.4),
  33. );
  34. return result;
  35. }
  36. }