delete_profile_confirm_dialog.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import 'package:flutter/Material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  4. import '../../../base/base_view.dart';
  5. import '../../../resource/assets.gen.dart';
  6. import '../../../resource/colors.gen.dart';
  7. import '../../../resource/string.gen.dart';
  8. import '../../../widget/gradient_btn.dart';
  9. import 'delete_profile_confirm_controller.dart';
  10. /// 确定时回调
  11. typedef OnConfirmCallback = void Function();
  12. /// 取消时回调
  13. typedef OnCancelCallback = void Function();
  14. /// 删除档案弹窗
  15. class DeleteProfileConfirmDialog {
  16. static const String _tag = "DeleteProfileConfirmDialog";
  17. /// 显示弹窗
  18. /// [targetName] Ta的名称
  19. /// [onConfirmCallback] 确认时回调
  20. static void show(String targetName, OnConfirmCallback onConfirmCallback) {
  21. SmartDialog.show(
  22. tag: _tag,
  23. // 点击遮罩,不关闭弹窗
  24. clickMaskDismiss: false,
  25. // 内容居中显示
  26. alignment: Alignment.center,
  27. // 动画类型
  28. animationType: SmartAnimationType.fade,
  29. builder:
  30. (BuildContext context) => IntrinsicHeight(
  31. child: Container(
  32. padding: EdgeInsets.symmetric(horizontal: 32.w),
  33. child: DeleteProfileConfirmView(
  34. targetName: targetName,
  35. onConfirmCallback: () {
  36. onConfirmCallback();
  37. SmartDialog.dismiss(tag: _tag);
  38. },
  39. onCancelCallback: () {
  40. // 关闭弹窗
  41. SmartDialog.dismiss(tag: _tag);
  42. },
  43. ),
  44. ),
  45. ),
  46. );
  47. }
  48. }
  49. /// 删除档案弹窗的内容
  50. class DeleteProfileConfirmView
  51. extends BaseView<DeleteProfileConfirmController> {
  52. final String targetName;
  53. final OnConfirmCallback onConfirmCallback;
  54. final OnCancelCallback onCancelCallback;
  55. const DeleteProfileConfirmView({
  56. super.key,
  57. required this.targetName,
  58. required this.onConfirmCallback,
  59. required this.onCancelCallback,
  60. });
  61. @override
  62. backgroundColor() => Colors.transparent;
  63. @override
  64. Widget buildBody(BuildContext context) {
  65. return Stack(
  66. children: [
  67. Container(
  68. padding: EdgeInsets.symmetric(vertical: 24.h, horizontal: 16.w),
  69. decoration: BoxDecoration(
  70. color: ColorName.white,
  71. borderRadius: BorderRadius.all(Radius.circular(16.r)),
  72. ),
  73. child: Column(
  74. // 包裹内容
  75. mainAxisSize: MainAxisSize.min,
  76. children: [
  77. // 标题
  78. _buildTitle(),
  79. SizedBox(height: 16.h),
  80. // 内容
  81. _buildContent(),
  82. SizedBox(height: 20.h),
  83. // 操作按钮
  84. _buildActionBtn(),
  85. ],
  86. ),
  87. ),
  88. Positioned(
  89. top: 0,
  90. right: 0,
  91. child: InkWell(
  92. onTap: () {
  93. controller.doOnCancel(onCancelCallback);
  94. },
  95. splashColor: ColorName.transparent,
  96. child: Container(
  97. padding: EdgeInsets.all(14.w),
  98. child: Assets.images.iconCustomDirectionEditClose.image(
  99. width: 24.w,
  100. height: 24.w,
  101. ),
  102. ),
  103. ),
  104. ),
  105. ],
  106. );
  107. }
  108. /// 标题
  109. Widget _buildTitle() {
  110. return Text(
  111. StringName.tipsDialogTitle,
  112. style: TextStyle(
  113. fontSize: 16.sp,
  114. color: ColorName.black80,
  115. fontWeight: FontWeight.bold,
  116. ),
  117. );
  118. }
  119. /// 输入框
  120. Widget _buildContent() {
  121. return Text(
  122. "确定要删除 $targetName 的档案吗?",
  123. style: TextStyle(
  124. fontSize: 14.sp,
  125. color: ColorName.black80,
  126. fontWeight: FontWeight.w400,
  127. ),
  128. );
  129. }
  130. /// 操作按钮
  131. Widget _buildActionBtn() {
  132. return Row(
  133. children: [
  134. // 取消
  135. Expanded(
  136. child: GradientTextBtn(
  137. StringName.dialogCancel,
  138. color: Color(0xFFF6F5FA),
  139. textColor: ColorName.black60,
  140. onPressed: () {
  141. controller.doOnCancel(onConfirmCallback);
  142. },
  143. ),
  144. ),
  145. SizedBox(width: 8.w),
  146. // 确定
  147. Expanded(
  148. child: GradientTextBtn(
  149. StringName.dialogConfirm,
  150. onPressed: () {
  151. controller.doOnConfirm(onConfirmCallback);
  152. },
  153. ),
  154. ),
  155. ],
  156. );
  157. }
  158. }