switch_project_dialog.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import 'package:cs_resources/generated/assets.dart';
  2. import 'package:domain/entity/response/index_option_entity.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  5. import 'package:get/get.dart';
  6. import 'package:widgets/ext/ex_widget.dart';
  7. import 'package:cs_resources/constants/color_constants.dart';
  8. import 'dart:ui';
  9. import 'package:flutter/cupertino.dart';
  10. import 'package:flutter/widgets.dart';
  11. import 'package:widgets/my_load_image.dart';
  12. import 'package:widgets/my_text_view.dart';
  13. import 'package:widgets/no_shadow_scroll_behavior.dart';
  14. import 'package:widgets/widget_export.dart';
  15. /*
  16. * 切换项目的弹窗
  17. */
  18. class SwitchProjectDialog extends StatefulWidget {
  19. final List<IndexOptionEntity> options;
  20. final void Function(IndexOptionEntity) confirmAction;
  21. final VoidCallback? cancelAction;
  22. SwitchProjectDialog({
  23. required this.options,
  24. required this.confirmAction,
  25. this.cancelAction,
  26. });
  27. @override
  28. _SwitchProjectDialogState createState() => _SwitchProjectDialogState();
  29. }
  30. class _SwitchProjectDialogState extends State<SwitchProjectDialog> {
  31. @override
  32. Widget build(BuildContext context) {
  33. return Column(
  34. crossAxisAlignment: CrossAxisAlignment.center,
  35. mainAxisAlignment: MainAxisAlignment.center,
  36. children: [
  37. Container(
  38. width: double.infinity,
  39. decoration: const BoxDecoration(
  40. color: Colors.white,
  41. borderRadius: BorderRadius.all(Radius.circular(15)),
  42. ),
  43. child: Column(
  44. children: [
  45. MyTextView(
  46. "Switch Projects".tr,
  47. fontSize: 19,
  48. isFontMedium: true,
  49. textColor: ColorConstants.black,
  50. marginTop: 15,
  51. marginBottom: 15,
  52. ),
  53. Scrollbar(
  54. child: ScrollConfiguration(
  55. behavior: NoShadowScrollBehavior(),
  56. child: SingleChildScrollView(
  57. child: Column(
  58. children: widget.options.map<Widget>((IndexOptionEntity option) {
  59. return InkWell(
  60. onTap: () {
  61. // 清除其他选项的 checked 状态
  62. for (var opt in widget.options) {
  63. opt.checked = null; // 清除所有选项的 checked 状态
  64. }
  65. option.checked = 'checked'; // 选中当前选项
  66. setState(() {}); // 刷新页面
  67. },
  68. child: Row(
  69. mainAxisSize: MainAxisSize.max,
  70. children: [
  71. MyTextView(
  72. option.txt ?? "",
  73. fontSize: 15,
  74. isFontRegular: true,
  75. textColor: ColorConstants.black33,
  76. ).expanded(),
  77. option.checked == "checked"
  78. ? const MyAssetImage(Assets.cptAuthCheckedIcon, width: 20.5, height: 20.5)
  79. : const MyAssetImage(Assets.cptAuthUncheckedIcon, width: 20.5, height: 20.5)
  80. ],
  81. ).paddingOnly(top: 12, bottom: 12, left: 20, right: 20),
  82. );
  83. }).toList(),
  84. ),
  85. ),
  86. ),
  87. ).constrained(maxHeight: 210),
  88. Container(
  89. margin: const EdgeInsets.only(top: 25),
  90. color: const Color(0XFFCECECE),
  91. height: 0.5,
  92. ),
  93. Row(
  94. children: [
  95. Expanded(
  96. flex: 1,
  97. child: InkWell(
  98. onTap: () {
  99. onCancel();
  100. widget.cancelAction?.call();
  101. },
  102. child: MyTextView(
  103. "Cancel".tr,
  104. fontSize: 17.5,
  105. isFontMedium: true,
  106. textAlign: TextAlign.center,
  107. textColor: const Color(0XFF0085C4),
  108. cornerRadius: 3,
  109. borderWidth: 1,
  110. ),
  111. ),
  112. ),
  113. Container(
  114. color: const Color(0xff09141F).withOpacity(0.13),
  115. width: 0.5,
  116. ),
  117. Expanded(
  118. flex: 1,
  119. child: InkWell(
  120. onTap: () async {
  121. onCancel();
  122. // 找到被选中的选项并触发确认操作
  123. final selectedOption = widget.options.firstWhereOrNull((opt) => opt.checked == 'checked');
  124. if (selectedOption != null) {
  125. widget.confirmAction(selectedOption);
  126. }
  127. },
  128. child: MyTextView(
  129. "Confirm".tr,
  130. marginLeft: 10,
  131. fontSize: 17.5,
  132. isFontMedium: true,
  133. textAlign: TextAlign.center,
  134. textColor: const Color(0XFF0085C4),
  135. cornerRadius: 3,
  136. ),
  137. ),
  138. ),
  139. ],
  140. ).constrained(height: 46),
  141. ],
  142. ),
  143. ),
  144. ],
  145. ).constrained(width: 295);
  146. }
  147. // 取消弹框
  148. void onCancel() async {
  149. SmartDialog.dismiss();
  150. }
  151. }