comments_dialog.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import 'package:flutter/material.dart';
  2. import 'package:cs_resources/generated/l10n.dart';
  3. import 'package:widgets/ext/ex_widget.dart';
  4. import 'package:cs_resources/theme/app_colors_theme.dart';
  5. import 'package:widgets/my_text_view.dart';
  6. import 'package:widgets/no_shadow_scroll_behavior.dart';
  7. import 'package:widgets/widget_export.dart';
  8. class CommentsDialog extends StatelessWidget {
  9. String? title;
  10. Widget? Function(BuildContext)? messageBuilder;
  11. VoidCallback confirmAction;
  12. VoidCallback? cancelAction;
  13. bool isShowCancelBtn;
  14. bool isShowConfirmBtn;
  15. String? confirmTxt;
  16. String? cancelTxt;
  17. double? height = 0.0;
  18. double? minHeight = 0.0;
  19. double? maxHeight;
  20. double? maxWidth = 300;
  21. CommentsDialog({
  22. this.title,
  23. Widget Function(BuildContext)? this.messageBuilder,
  24. required this.confirmAction,
  25. this.cancelAction,
  26. this.isShowCancelBtn = true,
  27. this.isShowConfirmBtn = true,
  28. this.confirmTxt,
  29. this.cancelTxt,
  30. height,
  31. minHeight,
  32. maxHeight,
  33. maxWidth,
  34. Key? key,
  35. }): height = height ?? 0.0,
  36. minHeight = minHeight ?? 0.0,
  37. maxHeight = maxHeight ?? 5000,
  38. maxWidth = maxWidth ?? 500,
  39. super(key: key);
  40. @override
  41. Widget build(BuildContext context) {
  42. final keyboardHeight = MediaQuery.of(context).viewInsets.bottom;
  43. return Container(
  44. width: double.infinity,
  45. constraints: BoxConstraints(
  46. minHeight: minHeight!,
  47. maxHeight: maxHeight!,
  48. maxWidth: maxWidth!,
  49. minWidth: 0.0,
  50. ),
  51. decoration: BoxDecoration(
  52. color: context.appColors.whiteSecondBG,
  53. borderRadius: const BorderRadius.only(
  54. topLeft: Radius.circular(0),
  55. topRight: Radius.circular(0),
  56. ),
  57. ),
  58. child: SingleChildScrollView(
  59. reverse: true, // 反向滚动,确保输入框在键盘上方
  60. child: Column(
  61. mainAxisSize: MainAxisSize.min,
  62. crossAxisAlignment: CrossAxisAlignment.center,
  63. children: [
  64. messageBuilder!(context) ?? Container(), // 处理 null 情况
  65. Visibility(
  66. visible: isShowConfirmBtn && isShowCancelBtn,
  67. child: Row(
  68. children: [
  69. const SizedBox(width: 18),
  70. Visibility(
  71. visible: isShowCancelBtn,
  72. child: Expanded(
  73. flex: 1,
  74. child: InkWell(
  75. onTap: () {
  76. onCancel();
  77. cancelAction?.call();
  78. },
  79. child: MyTextView(
  80. cancelTxt ?? S.current.no,
  81. fontSize: 16,
  82. isFontMedium: true,
  83. paddingTop: 13,
  84. marginRight: 15,
  85. paddingBottom: 13,
  86. textAlign: TextAlign.center,
  87. textColor: Colors.white,
  88. backgroundColor: context.appColors.orangeBG,
  89. cornerRadius: 7,
  90. ),
  91. ),
  92. ),
  93. ),
  94. Expanded(
  95. flex: 1,
  96. child: Visibility(
  97. visible: isShowConfirmBtn,
  98. child: InkWell(
  99. onTap: () async {
  100. onCancel();
  101. confirmAction();
  102. },
  103. child: MyTextView(
  104. confirmTxt ?? S.current.yes,
  105. fontSize: 16,
  106. paddingTop: 13,
  107. paddingBottom: 13,
  108. isFontMedium: true,
  109. textAlign: TextAlign.center,
  110. textColor: Colors.white,
  111. backgroundColor: context.appColors.btnBgDefault,
  112. cornerRadius: 7,
  113. ),
  114. ),
  115. ),
  116. ),
  117. const SizedBox(width: 18),
  118. ],
  119. ).marginOnly(bottom: 30, top: 28),
  120. ),
  121. ],
  122. ),
  123. ).marginOnly(
  124. bottom: keyboardHeight + 10,
  125. top: 5,
  126. ),
  127. );
  128. }
  129. // 取消弹框
  130. void onCancel() async {
  131. SmartDialog.dismiss();
  132. }
  133. }