dialog_confirm.dart 1.9 KB

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