dialog_confirm.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'alert_dialog.dart';
  4. /// 确认提示框
  5. class DialogConfirm extends StatelessWidget {
  6. /// 确认信息
  7. final String message;
  8. /// 标题,默认“提示”
  9. final String? title;
  10. /// 禁用取消按钮
  11. final bool disableCancel;
  12. const DialogConfirm({
  13. super.key,
  14. required this.message,
  15. this.disableCancel = false,
  16. this.title,
  17. });
  18. /// 弹出确认框
  19. ///
  20. /// [message] 确认信息
  21. ///
  22. /// [title] 标题,默认“提示”
  23. ///
  24. /// [disableCancel] 禁用取消按钮
  25. static Future<bool> show({
  26. required String message,
  27. String? title,
  28. bool disableCancel = false,
  29. }) async {
  30. final result = await Get.dialog(
  31. DialogConfirm(
  32. message: message,
  33. title: title,
  34. disableCancel: disableCancel,
  35. ),
  36. barrierDismissible: false,
  37. );
  38. return result == true;
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return VAlertDialog(
  43. title: title ?? "提示",
  44. width: 320,
  45. content: Column(
  46. // 自适应高度
  47. mainAxisSize: MainAxisSize.min,
  48. children: [
  49. Container(
  50. padding: const EdgeInsets.symmetric(horizontal: 24),
  51. alignment: Alignment.center,
  52. child: Row(
  53. children: [
  54. // 自适应换行
  55. Expanded(
  56. child: Text(
  57. message,
  58. style: const TextStyle(fontSize: 20),
  59. ),
  60. ),
  61. ],
  62. ),
  63. )
  64. ],
  65. ),
  66. onConfirm: () {
  67. Get.back(result: true);
  68. },
  69. showCancel: disableCancel == false,
  70. onCanceled: () {
  71. Get.back(result: false);
  72. },
  73. );
  74. }
  75. }