precode_save_dialog.dart 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  5. import 'package:screenshot/screenshot.dart';
  6. import 'package:nomo/app/widgets/click_opacity.dart';
  7. import '../../../../config/theme/dark_theme_colors.dart';
  8. import '../../../../config/translations/strings_enum.dart';
  9. import '../../../constants/assets.dart';
  10. import '../../../widgets/ix_image.dart';
  11. import '../../../widgets/submit_btn.dart';
  12. import '../controllers/precode_controller.dart';
  13. /// Pre Code 保存弹窗
  14. class PrecodeSaveDialog extends StatelessWidget {
  15. final PrecodeController controller;
  16. const PrecodeSaveDialog({super.key, required this.controller});
  17. @override
  18. Widget build(BuildContext context) {
  19. return _buildDialogContent();
  20. }
  21. /// 构建弹窗内容
  22. Widget _buildDialogContent() {
  23. return Padding(
  24. padding: EdgeInsets.all(24.w),
  25. child: Column(
  26. mainAxisSize: MainAxisSize.min,
  27. children: [
  28. Screenshot(
  29. controller: controller.screenshotController,
  30. child: Container(
  31. width: double.infinity,
  32. decoration: BoxDecoration(
  33. color: Get.reactiveTheme.highlightColor,
  34. borderRadius: BorderRadius.circular(20.r),
  35. ),
  36. child: Column(
  37. mainAxisSize: MainAxisSize.min,
  38. children: [
  39. // 内容区域
  40. Padding(
  41. padding: EdgeInsets.symmetric(
  42. horizontal: 10.w,
  43. vertical: 20.w,
  44. ),
  45. child: Column(
  46. mainAxisSize: MainAxisSize.min,
  47. children: [
  48. // Logo
  49. _buildLogo(),
  50. 10.verticalSpaceFromWidth,
  51. Divider(
  52. color: Get.reactiveTheme.dividerColor,
  53. height: 1.w,
  54. ),
  55. 10.verticalSpaceFromWidth,
  56. // Pre Code 标题和数字
  57. _buildPreCode(),
  58. 10.verticalSpaceFromWidth,
  59. Divider(
  60. color: Get.reactiveTheme.dividerColor,
  61. height: 1.w,
  62. ),
  63. 10.verticalSpaceFromWidth,
  64. // 说明文字
  65. _buildDescription(),
  66. 20.verticalSpaceFromWidth,
  67. // 安全提示
  68. _buildSecurityTip(),
  69. 20.verticalSpaceFromWidth,
  70. // UID 信息
  71. _buildUidInfo(),
  72. 10.verticalSpaceFromWidth,
  73. // Premium 标签
  74. _buildPremiumBadge(),
  75. ],
  76. ),
  77. ),
  78. ],
  79. ),
  80. ),
  81. ),
  82. 50.verticalSpaceFromWidth,
  83. // Save 按钮
  84. _buildSaveButton(),
  85. 20.verticalSpaceFromWidth,
  86. // Cancel 按钮
  87. _buildCancelButton(),
  88. ],
  89. ),
  90. );
  91. }
  92. /// Logo - 盾牌形状
  93. Widget _buildLogo() {
  94. return IXImage(
  95. source: Assets.splashLogo,
  96. width: 70.w,
  97. height: 94.w,
  98. sourceType: ImageSourceType.asset,
  99. );
  100. }
  101. /// Pre Code
  102. Widget _buildPreCode() {
  103. return Column(
  104. children: [
  105. Text(
  106. controller.preCode.value,
  107. style: TextStyle(
  108. fontSize: 28.sp,
  109. height: 1.2,
  110. fontWeight: FontWeight.w500,
  111. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  112. letterSpacing: 1.2,
  113. ),
  114. ),
  115. ],
  116. );
  117. }
  118. /// 说明文字
  119. Widget _buildDescription() {
  120. return Text(
  121. Strings.preCodeInfoMessage.tr,
  122. textAlign: TextAlign.center,
  123. style: TextStyle(
  124. fontSize: 14.sp,
  125. color: Get.reactiveTheme.hintColor,
  126. height: 1.4,
  127. ),
  128. );
  129. }
  130. /// 安全提示
  131. Widget _buildSecurityTip() {
  132. return Text(
  133. Strings.pleaseStoreSecurely.tr,
  134. textAlign: TextAlign.center,
  135. style: TextStyle(
  136. fontSize: 14.sp,
  137. color: Get.reactiveTheme.hintColor,
  138. height: 1.4,
  139. ),
  140. );
  141. }
  142. /// UID 信息
  143. Widget _buildUidInfo() {
  144. final uid = controller.uid;
  145. final displayUid = uid.length > 12
  146. ? 'UID ${uid.substring(0, 6)}***${uid.substring(uid.length - 6)}'
  147. : 'UID $uid';
  148. return Text(
  149. displayUid,
  150. style: TextStyle(
  151. fontSize: 14.sp,
  152. color: DarkThemeColors.validTermColor,
  153. height: 1.4,
  154. ),
  155. );
  156. }
  157. /// Premium 标签
  158. Widget _buildPremiumBadge() {
  159. return Obx(
  160. () => IXImage(
  161. source: controller.isPremium.value ? Assets.premium : Assets.free,
  162. width: controller.isPremium.value ? 92.w : 64.w,
  163. height: 28.w,
  164. sourceType: ImageSourceType.asset,
  165. ),
  166. );
  167. }
  168. /// Save 按钮
  169. Widget _buildSaveButton() {
  170. return SubmitButton(
  171. prefixIcon: IXImage(
  172. source: Assets.preCodeSaveLocal,
  173. width: 20.w,
  174. height: 20.w,
  175. sourceType: ImageSourceType.asset,
  176. ),
  177. text: Strings.save.tr,
  178. onPressed: controller.saveToGallery,
  179. );
  180. }
  181. /// Cancel 按钮
  182. Widget _buildCancelButton() {
  183. return ClickOpacity(
  184. onTap: () {
  185. Navigator.of(Get.context!).pop();
  186. },
  187. child: Container(
  188. height: 52.w,
  189. decoration: BoxDecoration(
  190. borderRadius: BorderRadius.circular(12.r),
  191. border: Border.all(color: Get.reactiveTheme.dividerColor, width: 1.w),
  192. ),
  193. alignment: Alignment.center,
  194. child: Text(
  195. Strings.cancel.tr,
  196. style: TextStyle(
  197. fontSize: 14.sp,
  198. fontWeight: FontWeight.w600,
  199. color: Get.reactiveTheme.hintColor,
  200. ),
  201. ),
  202. ),
  203. );
  204. }
  205. }
  206. /// 盾牌形状裁剪器
  207. class ShieldClipper extends CustomClipper<Path> {
  208. @override
  209. Path getClip(Size size) {
  210. final path = Path();
  211. final width = size.width;
  212. final height = size.height;
  213. // 绘制盾牌形状
  214. path.moveTo(width * 0.5, 0); // 顶部中心
  215. // 右上圆弧
  216. path.quadraticBezierTo(width * 0.75, 0, width, height * 0.2);
  217. // 右侧直线
  218. path.lineTo(width, height * 0.6);
  219. // 底部曲线到中心点
  220. path.quadraticBezierTo(width, height * 0.85, width * 0.5, height);
  221. // 从底部中心到左侧
  222. path.quadraticBezierTo(0, height * 0.85, 0, height * 0.6);
  223. // 左侧直线
  224. path.lineTo(0, height * 0.2);
  225. // 左上圆弧
  226. path.quadraticBezierTo(0, 0, width * 0.25, 0);
  227. path.close();
  228. return path;
  229. }
  230. @override
  231. bool shouldReclip(CustomClipper<Path> oldClipper) => false;
  232. }