confirm_box.dart 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. bool showCancel = true,
  12. }) async {
  13. final result = await Get.dialog(
  14. VAlertDialog(
  15. title: title ?? "提示",
  16. width: width ?? 320,
  17. content: Container(
  18. height: 32,
  19. padding: const EdgeInsets.symmetric(horizontal: 24),
  20. alignment: Alignment.center,
  21. child: Text(content, style: TextStyle(fontSize: 20)),
  22. ),
  23. onConfirm: () async {
  24. onConfirm?.call();
  25. Get.back(result: true);
  26. },
  27. onCanceled: () {
  28. onCancel?.call();
  29. return false;
  30. },
  31. showCancel: showCancel,
  32. ),
  33. barrierDismissible: false,
  34. barrierColor: Colors.black.withOpacity(.4),
  35. );
  36. return result;
  37. }
  38. static Future<bool> showMultiLines({
  39. String? title,
  40. required List<String> contents,
  41. VoidCallback? onConfirm,
  42. VoidCallback? onCancel,
  43. double? width,
  44. bool showCancel = true,
  45. }) async {
  46. final result = await Get.dialog(
  47. VAlertDialog(
  48. title: title ?? "提示",
  49. width: width ?? 320,
  50. content: Column(
  51. mainAxisSize: MainAxisSize.min,
  52. crossAxisAlignment: CrossAxisAlignment.start,
  53. mainAxisAlignment: MainAxisAlignment.start,
  54. children: [
  55. for (var content in contents)
  56. Container(
  57. height: 32,
  58. padding: const EdgeInsets.symmetric(horizontal: 24),
  59. alignment: Alignment.centerLeft,
  60. child: Text(content, style: TextStyle(fontSize: 20)),
  61. ),
  62. ],
  63. ),
  64. onConfirm: () async {
  65. onConfirm?.call();
  66. Get.back(result: true);
  67. },
  68. onCanceled: () {
  69. onCancel?.call();
  70. return false;
  71. },
  72. showCancel: showCancel,
  73. ),
  74. barrierDismissible: false,
  75. barrierColor: Colors.black.withOpacity(.4),
  76. );
  77. return result;
  78. }
  79. }