feedback_bottom_sheet.dart 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:nomo/app/widgets/click_opacity.dart';
  5. import '../widgets/submit_btn.dart';
  6. import 'all_dialog.dart';
  7. /// 反馈弹窗底部弹出框
  8. class FeedbackBottomSheet extends StatefulWidget {
  9. const FeedbackBottomSheet({super.key});
  10. /// 显示反馈弹窗
  11. static Future<void> show() {
  12. return Get.bottomSheet(
  13. const FeedbackBottomSheet(),
  14. backgroundColor: Colors.transparent,
  15. isDismissible: true,
  16. enableDrag: true,
  17. isScrollControlled: true,
  18. );
  19. }
  20. @override
  21. State<FeedbackBottomSheet> createState() => _FeedbackBottomSheetState();
  22. }
  23. class _FeedbackBottomSheetState extends State<FeedbackBottomSheet>
  24. with SingleTickerProviderStateMixin {
  25. // 选中的表情索引(0-4)
  26. int? selectedEmojiIndex;
  27. // 选中的问题标签
  28. final Set<String> selectedIssues = {};
  29. // 表情列表
  30. final List<String> emojis = ['😡', '😥', '🤭', '😏', '🥰'];
  31. // 每个表情对应的问题标签
  32. final Map<int, List<String>> emojiIssues = {
  33. 0: [
  34. // 差评 😡
  35. 'VPN connection failed',
  36. 'Internet too slow',
  37. 'Keeps disconnecting',
  38. 'App crashes or freezes',
  39. 'Other issues',
  40. ],
  41. 1: [
  42. // 一般偏差 😥
  43. 'Connection unstable',
  44. 'Speed not as expected',
  45. 'Hard to use / confusing UI',
  46. 'Other issues',
  47. ],
  48. 2: [
  49. // 中等 🤭
  50. 'Works fine but not fast enough',
  51. 'Limited free servers',
  52. 'App could be simpler',
  53. 'Sometimes disconnects',
  54. 'Nothing special',
  55. ],
  56. 3: [
  57. // 好 😏
  58. 'Easy to use',
  59. 'Fast connection',
  60. 'Stable performance',
  61. 'Useful free version',
  62. 'Satisfied overall',
  63. ],
  64. 4: [
  65. // 很好 🥰
  66. 'Fast and stable connection',
  67. 'Great user experience',
  68. 'Excellent premium features',
  69. 'Worth recommending',
  70. 'I love the design',
  71. ],
  72. };
  73. @override
  74. Widget build(BuildContext context) {
  75. return Container(
  76. decoration: BoxDecoration(
  77. color: Get.theme.highlightColor,
  78. borderRadius: BorderRadius.only(
  79. topLeft: Radius.circular(16.r),
  80. topRight: Radius.circular(16.r),
  81. ),
  82. ),
  83. child: SafeArea(
  84. child: Column(
  85. mainAxisSize: MainAxisSize.min,
  86. children: [
  87. // 关闭按钮
  88. _buildCloseButton(),
  89. // 标题
  90. _buildTitle(),
  91. 10.verticalSpaceFromWidth,
  92. // 副标题
  93. _buildSubtitle(),
  94. 10.verticalSpaceFromWidth,
  95. // 表情选择器
  96. _buildEmojiSelector(),
  97. // 问题标签区域 - 使用 AnimatedSize 实现平滑高度过渡
  98. AnimatedSize(
  99. duration: const Duration(milliseconds: 300),
  100. curve: Curves.easeInOut,
  101. child: selectedEmojiIndex != null
  102. ? Column(
  103. mainAxisSize: MainAxisSize.min,
  104. children: [24.verticalSpaceFromWidth, _buildIssueTags()],
  105. )
  106. : const SizedBox.shrink(),
  107. ),
  108. // 发送按钮 - 使用 AnimatedSize 实现平滑显示/隐藏
  109. AnimatedSize(
  110. duration: const Duration(milliseconds: 300),
  111. curve: Curves.easeInOut,
  112. child: selectedEmojiIndex != null
  113. ? _buildSendButton()
  114. : 24.verticalSpaceFromWidth,
  115. ),
  116. ],
  117. ),
  118. ),
  119. );
  120. }
  121. /// 构建关闭按钮
  122. Widget _buildCloseButton() {
  123. return Align(
  124. alignment: Alignment.centerRight,
  125. child: ClickOpacity(
  126. onTap: () => Navigator.of(Get.context!).pop(),
  127. child: Container(
  128. width: 24.w,
  129. height: 24.w,
  130. margin: EdgeInsets.only(right: 8.w, top: 8.w),
  131. padding: EdgeInsets.all(4.w),
  132. decoration: BoxDecoration(
  133. color: Get.theme.cardColor,
  134. shape: BoxShape.circle,
  135. ),
  136. child: Icon(
  137. Icons.close_rounded,
  138. size: 16.w,
  139. color: Get.theme.textTheme.bodyLarge!.color,
  140. ),
  141. ),
  142. ),
  143. );
  144. }
  145. /// 构建标题
  146. Widget _buildTitle() {
  147. return Text(
  148. "How's your\nexperience so far ?",
  149. textAlign: TextAlign.center,
  150. style: TextStyle(
  151. fontSize: 22.sp,
  152. fontWeight: FontWeight.w500,
  153. color: Get.theme.textTheme.bodyLarge!.color,
  154. height: 1.3,
  155. ),
  156. );
  157. }
  158. /// 构建副标题
  159. Widget _buildSubtitle() {
  160. return Text(
  161. "we'd love to know !",
  162. textAlign: TextAlign.center,
  163. style: TextStyle(
  164. fontSize: 16.sp,
  165. height: 1.4,
  166. color: Get.theme.hintColor,
  167. ),
  168. );
  169. }
  170. /// 构建表情选择器
  171. Widget _buildEmojiSelector() {
  172. return Row(
  173. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  174. children: List.generate(
  175. emojis.length,
  176. (index) => _buildEmojiButton(index),
  177. ),
  178. );
  179. }
  180. /// 构建单个表情按钮
  181. Widget _buildEmojiButton(int index) {
  182. final isSelected = selectedEmojiIndex == index;
  183. return ClickOpacity(
  184. onTap: () {
  185. setState(() {
  186. if (selectedEmojiIndex == index) {
  187. // 如果点击已选中的表情,取消选择
  188. selectedEmojiIndex = null;
  189. } else {
  190. // 选择新的表情
  191. selectedEmojiIndex = index;
  192. }
  193. // 切换表情时清空已选的问题标签
  194. selectedIssues.clear();
  195. });
  196. },
  197. child: Container(
  198. width: 56.w,
  199. height: 56.w,
  200. decoration: BoxDecoration(
  201. shape: BoxShape.circle,
  202. color: isSelected ? Get.theme.cardColor : Colors.transparent,
  203. border: Border.all(
  204. color: isSelected ? Get.theme.dividerColor : Colors.transparent,
  205. width: 1.w,
  206. ),
  207. ),
  208. alignment: Alignment.center,
  209. child: Text(emojis[index], style: TextStyle(fontSize: 32.sp)),
  210. ),
  211. );
  212. }
  213. /// 构建问题标签
  214. Widget _buildIssueTags() {
  215. if (selectedEmojiIndex == null) return const SizedBox.shrink();
  216. final issues = emojiIssues[selectedEmojiIndex!] ?? [];
  217. return Padding(
  218. padding: EdgeInsets.symmetric(horizontal: 24.w),
  219. child: Wrap(
  220. spacing: 10.w,
  221. runSpacing: 10.h,
  222. alignment: WrapAlignment.center,
  223. children: issues.map((issue) => _buildIssueTag(issue)).toList(),
  224. ),
  225. );
  226. }
  227. /// 构建单个问题标签
  228. Widget _buildIssueTag(String issue) {
  229. final isSelected = selectedIssues.contains(issue);
  230. return ClickOpacity(
  231. onTap: () {
  232. setState(() {
  233. if (isSelected) {
  234. selectedIssues.remove(issue);
  235. } else {
  236. selectedIssues.add(issue);
  237. }
  238. });
  239. },
  240. child: AnimatedContainer(
  241. duration: const Duration(milliseconds: 200),
  242. padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 8.h),
  243. decoration: BoxDecoration(
  244. color: isSelected ? Get.theme.primaryColor : Get.theme.cardColor,
  245. borderRadius: BorderRadius.circular(24.r),
  246. border: Border.all(
  247. color: isSelected ? Get.theme.primaryColor : Get.theme.dividerColor,
  248. width: 1.w,
  249. ),
  250. ),
  251. child: Text(
  252. issue,
  253. style: TextStyle(
  254. fontSize: 14.sp,
  255. color: isSelected
  256. ? Get.theme.textTheme.bodyLarge!.color
  257. : Get.theme.hintColor,
  258. ),
  259. ),
  260. ),
  261. );
  262. }
  263. /// 构建发送按钮
  264. Widget _buildSendButton() {
  265. // 必须选中表情并且选中至少一个问题标签才能发送
  266. final canSend = selectedEmojiIndex != null && selectedIssues.isNotEmpty;
  267. return Container(
  268. margin: EdgeInsets.only(left: 24.w, right: 24.w, top: 24.h, bottom: 10.w),
  269. child: SubmitButton(
  270. text: 'Send',
  271. enabled: canSend,
  272. onPressed: canSend ? _handleSend : null,
  273. ),
  274. );
  275. }
  276. /// 处理发送
  277. void _handleSend() {
  278. Navigator.of(Get.context!).pop();
  279. // 显示成功提示
  280. AllDialog.showFeedback();
  281. }
  282. }