feedback_bottom_sheet.dart 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 'submit_btn.dart';
  6. /// 反馈弹窗底部弹出框
  7. class FeedbackBottomSheet extends StatefulWidget {
  8. const FeedbackBottomSheet({super.key});
  9. /// 显示反馈弹窗
  10. static Future<void> show() {
  11. return Get.bottomSheet(
  12. const FeedbackBottomSheet(),
  13. backgroundColor: Colors.transparent,
  14. isDismissible: true,
  15. enableDrag: true,
  16. isScrollControlled: true,
  17. );
  18. }
  19. @override
  20. State<FeedbackBottomSheet> createState() => _FeedbackBottomSheetState();
  21. }
  22. class _FeedbackBottomSheetState extends State<FeedbackBottomSheet>
  23. with SingleTickerProviderStateMixin {
  24. // 选中的表情索引(0-4)
  25. int? selectedEmojiIndex;
  26. // 选中的问题标签
  27. final Set<String> selectedIssues = {};
  28. // 表情列表
  29. final List<String> emojis = ['😡', '😥', '🤭', '😏', '🥰'];
  30. // 每个表情对应的问题标签
  31. final Map<int, List<String>> emojiIssues = {
  32. 0: [
  33. // 差评 😡
  34. 'VPN connection failed',
  35. 'Internet too slow',
  36. 'Keeps disconnecting',
  37. 'App crashes or freezes',
  38. 'Other issues',
  39. ],
  40. 1: [
  41. // 一般偏差 😥
  42. 'Connection unstable',
  43. 'Speed not as expected',
  44. 'Hard to use / confusing UI',
  45. 'Other issues',
  46. ],
  47. 2: [
  48. // 中等 🤭
  49. 'Works fine but not fast enough',
  50. 'Limited free servers',
  51. 'App could be simpler',
  52. 'Sometimes disconnects',
  53. 'Nothing special',
  54. ],
  55. 3: [
  56. // 好 😏
  57. 'Easy to use',
  58. 'Fast connection',
  59. 'Stable performance',
  60. 'Useful free version',
  61. 'Satisfied overall',
  62. ],
  63. 4: [
  64. // 很好 🥰
  65. 'Fast and stable connection',
  66. 'Great user experience',
  67. 'Excellent premium features',
  68. 'Worth recommending',
  69. 'I love the design',
  70. ],
  71. };
  72. @override
  73. Widget build(BuildContext context) {
  74. return Container(
  75. decoration: BoxDecoration(
  76. color: Get.theme.highlightColor,
  77. borderRadius: BorderRadius.only(
  78. topLeft: Radius.circular(16.r),
  79. topRight: Radius.circular(16.r),
  80. ),
  81. ),
  82. child: SafeArea(
  83. child: Column(
  84. mainAxisSize: MainAxisSize.min,
  85. children: [
  86. // 关闭按钮
  87. _buildCloseButton(),
  88. // 标题
  89. _buildTitle(),
  90. 10.verticalSpaceFromWidth,
  91. // 副标题
  92. _buildSubtitle(),
  93. 10.verticalSpaceFromWidth,
  94. // 表情选择器
  95. _buildEmojiSelector(),
  96. // 问题标签区域 - 使用 AnimatedSize 实现平滑高度过渡
  97. AnimatedSize(
  98. duration: const Duration(milliseconds: 300),
  99. curve: Curves.easeInOut,
  100. child: selectedEmojiIndex != null
  101. ? Column(
  102. mainAxisSize: MainAxisSize.min,
  103. children: [24.verticalSpaceFromWidth, _buildIssueTags()],
  104. )
  105. : const SizedBox.shrink(),
  106. ),
  107. // 发送按钮 - 使用 AnimatedSize 实现平滑显示/隐藏
  108. AnimatedSize(
  109. duration: const Duration(milliseconds: 300),
  110. curve: Curves.easeInOut,
  111. child: selectedEmojiIndex != null
  112. ? _buildSendButton()
  113. : 24.verticalSpaceFromWidth,
  114. ),
  115. ],
  116. ),
  117. ),
  118. );
  119. }
  120. /// 构建关闭按钮
  121. Widget _buildCloseButton() {
  122. return Align(
  123. alignment: Alignment.centerRight,
  124. child: ClickOpacity(
  125. onTap: () => Navigator.of(Get.context!).pop(),
  126. child: Container(
  127. width: 24.w,
  128. height: 24.w,
  129. margin: EdgeInsets.only(right: 8.w, top: 8.w),
  130. padding: EdgeInsets.all(4.w),
  131. decoration: BoxDecoration(
  132. color: Get.theme.cardColor,
  133. shape: BoxShape.circle,
  134. ),
  135. child: Icon(
  136. Icons.close_rounded,
  137. size: 16.w,
  138. color: Get.theme.textTheme.bodyLarge!.color,
  139. ),
  140. ),
  141. ),
  142. );
  143. }
  144. /// 构建标题
  145. Widget _buildTitle() {
  146. return Text(
  147. "How's your\nexperience so far ?",
  148. textAlign: TextAlign.center,
  149. style: TextStyle(
  150. fontSize: 22.sp,
  151. fontWeight: FontWeight.w500,
  152. color: Get.theme.textTheme.bodyLarge!.color,
  153. height: 1.3,
  154. ),
  155. );
  156. }
  157. /// 构建副标题
  158. Widget _buildSubtitle() {
  159. return Text(
  160. "we'd love to know !",
  161. textAlign: TextAlign.center,
  162. style: TextStyle(
  163. fontSize: 16.sp,
  164. height: 1.4,
  165. color: Get.theme.hintColor,
  166. ),
  167. );
  168. }
  169. /// 构建表情选择器
  170. Widget _buildEmojiSelector() {
  171. return Row(
  172. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  173. children: List.generate(
  174. emojis.length,
  175. (index) => _buildEmojiButton(index),
  176. ),
  177. );
  178. }
  179. /// 构建单个表情按钮
  180. Widget _buildEmojiButton(int index) {
  181. final isSelected = selectedEmojiIndex == index;
  182. return ClickOpacity(
  183. onTap: () {
  184. setState(() {
  185. if (selectedEmojiIndex == index) {
  186. // 如果点击已选中的表情,取消选择
  187. selectedEmojiIndex = null;
  188. } else {
  189. // 选择新的表情
  190. selectedEmojiIndex = index;
  191. }
  192. // 切换表情时清空已选的问题标签
  193. selectedIssues.clear();
  194. });
  195. },
  196. child: AnimatedContainer(
  197. duration: const Duration(milliseconds: 200),
  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. // TODO: 这里可以添加发送反馈的逻辑
  279. Get.back();
  280. // 显示成功提示
  281. Get.snackbar(
  282. 'Thank you!',
  283. 'Your feedback has been submitted.',
  284. snackPosition: SnackPosition.bottom,
  285. backgroundColor: Get.theme.primaryColor,
  286. colorText: Colors.white,
  287. margin: EdgeInsets.all(16.w),
  288. borderRadius: 12.r,
  289. duration: const Duration(seconds: 2),
  290. );
  291. }
  292. }