precode_save_dialog.dart 6.9 KB

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