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 '../../../../config/translations/strings_enum.dart';
  9. import '../../../../utils/formater.dart';
  10. import '../../../constants/assets.dart';
  11. import '../../../widgets/ix_image.dart';
  12. import '../../../widgets/submit_btn.dart';
  13. import '../controllers/precode_controller.dart';
  14. /// Pre Code 保存弹窗
  15. class PrecodeSaveDialog extends StatelessWidget {
  16. final PrecodeController controller;
  17. const PrecodeSaveDialog({super.key, required this.controller});
  18. @override
  19. Widget build(BuildContext context) {
  20. return _buildDialogContent();
  21. }
  22. /// 构建弹窗内容
  23. Widget _buildDialogContent() {
  24. return Padding(
  25. padding: EdgeInsets.all(24.w),
  26. child: Column(
  27. mainAxisSize: MainAxisSize.min,
  28. children: [
  29. Screenshot(
  30. controller: controller.screenshotController,
  31. child: Container(
  32. width: double.infinity,
  33. decoration: BoxDecoration(
  34. color: Get.reactiveTheme.highlightColor,
  35. borderRadius: BorderRadius.circular(20.r),
  36. ),
  37. child: Column(
  38. mainAxisSize: MainAxisSize.min,
  39. children: [
  40. // 内容区域
  41. Padding(
  42. padding: EdgeInsets.symmetric(
  43. horizontal: 10.w,
  44. vertical: 20.w,
  45. ),
  46. child: Column(
  47. mainAxisSize: MainAxisSize.min,
  48. children: [
  49. // Logo
  50. _buildLogo(),
  51. 10.verticalSpaceFromWidth,
  52. Divider(
  53. color: Get.reactiveTheme.dividerColor,
  54. height: 1.w,
  55. ),
  56. 10.verticalSpaceFromWidth,
  57. // Pre Code 标题和数字
  58. _buildPreCode(),
  59. 10.verticalSpaceFromWidth,
  60. Divider(
  61. color: Get.reactiveTheme.dividerColor,
  62. height: 1.w,
  63. ),
  64. 10.verticalSpaceFromWidth,
  65. // 说明文字
  66. _buildDescription(),
  67. 20.verticalSpaceFromWidth,
  68. // 安全提示
  69. _buildSecurityTip(),
  70. 20.verticalSpaceFromWidth,
  71. // UID 信息
  72. _buildUidInfo(),
  73. 10.verticalSpaceFromWidth,
  74. // Premium 标签
  75. _buildPremiumBadge(),
  76. ],
  77. ),
  78. ),
  79. ],
  80. ),
  81. ),
  82. ),
  83. 50.verticalSpaceFromWidth,
  84. // Save 按钮
  85. _buildSaveButton(),
  86. 20.verticalSpaceFromWidth,
  87. // Cancel 按钮
  88. _buildCancelButton(),
  89. ],
  90. ),
  91. );
  92. }
  93. /// Logo - 盾牌形状
  94. Widget _buildLogo() {
  95. return IXImage(
  96. source: Assets.splashLogo,
  97. width: 70.w,
  98. height: 94.w,
  99. sourceType: ImageSourceType.asset,
  100. );
  101. }
  102. /// Pre Code
  103. Widget _buildPreCode() {
  104. return Column(
  105. children: [
  106. Text(
  107. controller.preCode.value,
  108. style: TextStyle(
  109. fontSize: 28.sp,
  110. height: 1.2,
  111. fontWeight: FontWeight.w500,
  112. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  113. letterSpacing: 1.2,
  114. ),
  115. ),
  116. ],
  117. );
  118. }
  119. /// 说明文字
  120. Widget _buildDescription() {
  121. return Text(
  122. Strings.preCodeInfoMessage.tr,
  123. textAlign: TextAlign.center,
  124. style: TextStyle(
  125. fontSize: 14.sp,
  126. color: Get.reactiveTheme.hintColor,
  127. height: 1.4,
  128. ),
  129. );
  130. }
  131. /// 安全提示
  132. Widget _buildSecurityTip() {
  133. return Text(
  134. Strings.pleaseStoreSecurely.tr,
  135. textAlign: TextAlign.center,
  136. style: TextStyle(
  137. fontSize: 14.sp,
  138. color: Get.reactiveTheme.hintColor,
  139. height: 1.4,
  140. ),
  141. );
  142. }
  143. /// UID 信息
  144. Widget _buildUidInfo() {
  145. final uid = controller.uid;
  146. final displayUid = 'UID ${formatDeviceId(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 : 92.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: Strings.save.tr,
  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. Strings.cancel.tr,
  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. }