subscription_view.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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/constants/iconfont/iconfont.dart';
  5. import 'package:nomo/config/theme/dark_theme_colors.dart';
  6. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  7. import 'package:video_player/video_player.dart';
  8. import '../../../../config/translations/strings_enum.dart';
  9. import '../../../constants/assets.dart';
  10. import '../../../widgets/info_card.dart';
  11. import '../../../widgets/ix_image.dart';
  12. import '../controllers/subscription_controller.dart';
  13. class SubscriptionView extends GetView<SubscriptionController> {
  14. const SubscriptionView({super.key});
  15. @override
  16. Widget build(BuildContext context) {
  17. return Scaffold(
  18. backgroundColor: DarkThemeColors.scaffoldBackgroundColor,
  19. body: Stack(
  20. children: [
  21. // 视频背景层(只显示顶部214高度)
  22. Obx(() {
  23. if (controller.isVideoInitialized.value) {
  24. return Positioned(
  25. top: 0,
  26. left: 0,
  27. right: 0,
  28. height: 214.w,
  29. child: ClipRect(
  30. child: FittedBox(
  31. fit: BoxFit.cover,
  32. child: SizedBox(
  33. width: controller.videoController.value.size.width,
  34. height: controller.videoController.value.size.height,
  35. child: VideoPlayer(controller.videoController),
  36. ),
  37. ),
  38. ),
  39. );
  40. }
  41. return const SizedBox.shrink();
  42. }),
  43. // 渐变遮罩层(只在视频区域)
  44. Positioned(
  45. top: 0,
  46. left: 0,
  47. right: 0,
  48. height: 214.w,
  49. child: Container(
  50. decoration: BoxDecoration(
  51. gradient: LinearGradient(
  52. begin: Alignment.topCenter,
  53. end: Alignment.bottomCenter,
  54. colors: [Colors.black.withValues(alpha: 0.6), Colors.black],
  55. stops: const [0.0, 1.0],
  56. ),
  57. ),
  58. ),
  59. ),
  60. // 内容层
  61. SafeArea(
  62. child: Column(
  63. children: [
  64. _buildAppBar(),
  65. Expanded(
  66. child: SingleChildScrollView(
  67. padding: EdgeInsets.symmetric(horizontal: 20.w),
  68. child: Column(
  69. crossAxisAlignment: CrossAxisAlignment.start,
  70. children: [
  71. 16.verticalSpaceFromWidth,
  72. _buildCurrentSubscription(),
  73. 24.verticalSpaceFromWidth,
  74. _buildPlanOptions(),
  75. _buildPlanChangeInfo(),
  76. 16.verticalSpaceFromWidth,
  77. _buildPremiumFeatures(),
  78. 16.verticalSpaceFromWidth,
  79. ],
  80. ),
  81. ),
  82. ),
  83. _buildBottomSection(),
  84. ],
  85. ),
  86. ),
  87. ],
  88. ),
  89. );
  90. }
  91. // 顶部标题栏
  92. Widget _buildAppBar() {
  93. return Padding(
  94. padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 12.h),
  95. child: Row(
  96. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  97. children: [
  98. SizedBox(width: 32.w),
  99. Text(
  100. Strings.subscription.tr,
  101. style: TextStyle(
  102. fontSize: 16.sp,
  103. height: 1.4,
  104. fontWeight: FontWeight.w500,
  105. color: Colors.white,
  106. ),
  107. ),
  108. GestureDetector(
  109. onTap: () => Get.back(),
  110. child: Container(
  111. width: 24.w,
  112. height: 24.w,
  113. decoration: BoxDecoration(
  114. color: Colors.white.withValues(alpha: 0.1),
  115. shape: BoxShape.circle,
  116. ),
  117. child: Icon(Icons.close_rounded, color: Colors.white, size: 16.w),
  118. ),
  119. ),
  120. ],
  121. ),
  122. );
  123. }
  124. // 当前订阅信息
  125. Widget _buildCurrentSubscription() {
  126. return Row(
  127. children: [
  128. // 钻石图标
  129. IXImage(
  130. source: Assets.subscriptionDiamond,
  131. width: 92.w,
  132. height: 80.w,
  133. sourceType: ImageSourceType.asset,
  134. ),
  135. 12.horizontalSpace,
  136. Expanded(
  137. child: Column(
  138. crossAxisAlignment: CrossAxisAlignment.start,
  139. children: [
  140. Row(
  141. children: [
  142. IXImage(
  143. source: Assets.subscriptionWallet,
  144. width: 20.w,
  145. height: 20.w,
  146. sourceType: ImageSourceType.asset,
  147. ),
  148. 4.horizontalSpace,
  149. Text(
  150. Strings.currentSubscription.tr,
  151. style: TextStyle(
  152. fontSize: 14.sp,
  153. height: 1.4,
  154. color: DarkThemeColors.subscriptionColor,
  155. fontWeight: FontWeight.w700,
  156. ),
  157. ),
  158. ],
  159. ),
  160. 10.verticalSpaceFromWidth,
  161. Text(
  162. Strings.yearPlanPrice.trParams({'price': '\$40.00'}),
  163. style: TextStyle(
  164. fontSize: 14.sp,
  165. height: 1.4,
  166. color: Colors.white,
  167. ),
  168. ),
  169. ],
  170. ),
  171. ),
  172. ],
  173. );
  174. }
  175. // 订阅计划选项
  176. Widget _buildPlanOptions() {
  177. return Obx(
  178. () => Column(
  179. children: List.generate(
  180. controller.plans.length,
  181. (index) => _buildPlanItem(
  182. controller.plans[index],
  183. index,
  184. controller.selectedPlanIndex.value == index,
  185. ),
  186. ),
  187. ),
  188. );
  189. }
  190. Widget _buildPlanItem(Map<String, dynamic> plan, int index, bool isSelected) {
  191. final badge = plan['badge'] as String?;
  192. final badgeBgColor = plan['badgeBgColor'] as Color?;
  193. final badgeTextColor = plan['badgeTextColor'] as Color?;
  194. final badgeBorderColor = plan['badgeBorderColor'] as Color?;
  195. return GestureDetector(
  196. onTap: () => controller.selectPlan(index),
  197. child: Container(
  198. margin: EdgeInsets.only(bottom: 18.w),
  199. decoration: BoxDecoration(
  200. color: DarkThemeColors.cardColor,
  201. borderRadius: BorderRadius.circular(12.r),
  202. border: Border.all(
  203. color: isSelected
  204. ? DarkThemeColors.subscriptionColor
  205. : DarkThemeColors.dividerColor,
  206. width: 2.w,
  207. ),
  208. ),
  209. child: Stack(
  210. clipBehavior: Clip.none,
  211. children: [
  212. // 主要内容
  213. Padding(
  214. padding: EdgeInsets.all(10.w),
  215. child: Row(
  216. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  217. children: [
  218. Column(
  219. crossAxisAlignment: CrossAxisAlignment.start,
  220. children: [
  221. Text(
  222. plan['price'] as String,
  223. style: TextStyle(
  224. fontSize: 18.sp,
  225. height: 1.4,
  226. color: DarkThemeColors.bodyTextColor,
  227. fontWeight: FontWeight.w600,
  228. ),
  229. ),
  230. Text(
  231. plan['period'] as String,
  232. style: TextStyle(
  233. fontSize: 12.sp,
  234. height: 1.6,
  235. color: DarkThemeColors.hintTextColor,
  236. ),
  237. ),
  238. ],
  239. ),
  240. Row(
  241. children: [
  242. Text(
  243. plan['title'] as String,
  244. style: TextStyle(
  245. fontSize: 13.sp,
  246. height: 1.4,
  247. color: DarkThemeColors.bodyTextColor,
  248. ),
  249. ),
  250. 8.horizontalSpace,
  251. Container(
  252. width: 20.w,
  253. height: 20.w,
  254. decoration: BoxDecoration(
  255. shape: BoxShape.circle,
  256. border: Border.all(
  257. color: isSelected
  258. ? DarkThemeColors.primaryColor
  259. : Colors.white30,
  260. width: 1.5.w,
  261. ),
  262. color: isSelected
  263. ? DarkThemeColors.primaryColor
  264. : Colors.transparent,
  265. ),
  266. child: isSelected
  267. ? Icon(Icons.check, color: Colors.white, size: 12.w)
  268. : null,
  269. ),
  270. ],
  271. ),
  272. ],
  273. ),
  274. ),
  275. // 标签固定在右上角,压在边框线上
  276. if (badge != null)
  277. Positioned(
  278. top: -11.h, // 负值让标签向上移动,压在边框线上
  279. right: 12.w,
  280. child: Container(
  281. padding: EdgeInsets.symmetric(horizontal: 6.w),
  282. decoration: BoxDecoration(
  283. color: badgeBgColor ?? Colors.black,
  284. borderRadius: BorderRadius.circular(4.r),
  285. border: badgeBorderColor != null
  286. ? Border.all(color: badgeBorderColor, width: 1)
  287. : null,
  288. ),
  289. child: Text(
  290. badge,
  291. style: TextStyle(
  292. fontSize: 12.sp,
  293. color: badgeTextColor ?? Colors.white,
  294. height: 1.6,
  295. ),
  296. ),
  297. ),
  298. ),
  299. ],
  300. ),
  301. ),
  302. );
  303. }
  304. // 计划变更信息
  305. Widget _buildPlanChangeInfo() {
  306. return InfoCard(
  307. title: Strings.planChangeInfo.tr,
  308. items: [
  309. InfoItem(
  310. imageSource: Assets.subscriptionPlanChange1,
  311. title: Strings.whenItStarts.tr,
  312. description: Strings.yourNewPlanBeginsRightAway.tr,
  313. iconColor: DarkThemeColors.primaryColor,
  314. ),
  315. InfoItem(
  316. imageSource: Assets.subscriptionPlanChange2,
  317. title: Strings.whatHappensToYourBalance.tr,
  318. description: Strings.anyUnusedAmountFromYourOldPlan.tr,
  319. iconColor: DarkThemeColors.primaryColor,
  320. ),
  321. InfoItem(
  322. imageSource: Assets.subscriptionPlanChange3,
  323. title: Strings.extraTime.tr,
  324. description: Strings.youllGetExtraDays.tr,
  325. iconColor: DarkThemeColors.primaryColor,
  326. ),
  327. ],
  328. );
  329. }
  330. // Premium 功能列表
  331. Widget _buildPremiumFeatures() {
  332. return Column(
  333. crossAxisAlignment: CrossAxisAlignment.start,
  334. children: [
  335. Text(
  336. Strings.premiumsIncluded.tr,
  337. style: TextStyle(
  338. fontSize: 16.sp,
  339. color: DarkThemeColors.subscriptionColor,
  340. fontWeight: FontWeight.w500,
  341. ),
  342. ),
  343. 16.verticalSpace,
  344. Container(
  345. padding: EdgeInsets.symmetric(vertical: 4.w, horizontal: 10.w),
  346. decoration: BoxDecoration(
  347. color: DarkThemeColors.bgDisable,
  348. borderRadius: BorderRadius.circular(12.r),
  349. ),
  350. child: Column(
  351. children: [
  352. _buildFeatureItem(
  353. IconFont.icon60,
  354. Strings.unlockAllFreeLocations.tr,
  355. ),
  356. _buildFeatureItem(IconFont.icon61, Strings.unlockSmartMode.tr),
  357. _buildFeatureItem(IconFont.icon62, Strings.unlockMultiHopMode.tr),
  358. _buildFeatureItem(
  359. IconFont.icon63,
  360. Strings.premiumCanShareXDevices.tr,
  361. ),
  362. _buildFeatureItem(
  363. IconFont.icon64,
  364. Strings.ownYourOwnPrivateServer.tr,
  365. ),
  366. _buildFeatureItem(IconFont.icon65, Strings.closeAds.tr),
  367. ],
  368. ),
  369. ),
  370. ],
  371. );
  372. }
  373. Widget _buildFeatureItem(IconData icon, String title) {
  374. return SizedBox(
  375. height: 44.w,
  376. child: Row(
  377. children: [
  378. Icon(icon, color: DarkThemeColors.subscriptionColor, size: 24.w),
  379. 12.horizontalSpace,
  380. Expanded(
  381. child: Text(
  382. title,
  383. style: TextStyle(
  384. fontSize: 13.sp,
  385. color: Get.reactiveTheme.hintColor,
  386. ),
  387. ),
  388. ),
  389. Container(
  390. width: 20.w,
  391. height: 20.w,
  392. decoration: BoxDecoration(
  393. shape: BoxShape.circle,
  394. color: DarkThemeColors.subscriptionSelectColor,
  395. ),
  396. child: Icon(Icons.check, color: Colors.white, size: 12.w),
  397. ),
  398. ],
  399. ),
  400. );
  401. }
  402. // 底部按钮区域
  403. Widget _buildBottomSection() {
  404. return Container(
  405. padding: EdgeInsets.symmetric(vertical: 10.w, horizontal: 14.w),
  406. decoration: BoxDecoration(
  407. border: Border(
  408. top: BorderSide(color: Colors.white.withOpacity(0.1), width: 1),
  409. ),
  410. ),
  411. child: Column(
  412. mainAxisSize: MainAxisSize.min,
  413. children: [
  414. // 确认按钮
  415. GestureDetector(
  416. onTap: controller.confirmChange,
  417. child: Container(
  418. width: double.infinity,
  419. height: 48.h,
  420. decoration: BoxDecoration(
  421. color: DarkThemeColors.backgroundColor,
  422. borderRadius: BorderRadius.circular(12.r),
  423. ),
  424. child: Center(
  425. child: Text(
  426. Strings.confirmChange.tr,
  427. style: TextStyle(
  428. fontSize: 16.sp,
  429. color: DarkThemeColors.subscriptionColor,
  430. fontWeight: FontWeight.w600,
  431. ),
  432. ),
  433. ),
  434. ),
  435. ),
  436. 14.verticalSpaceFromWidth,
  437. // 底部链接
  438. Row(
  439. mainAxisAlignment: MainAxisAlignment.center,
  440. children: [
  441. GestureDetector(
  442. onTap: controller.restorePurchases,
  443. child: Text(
  444. Strings.restorePurchases.tr,
  445. style: TextStyle(
  446. fontSize: 16.sp,
  447. color: DarkThemeColors.bodyTextColor,
  448. ),
  449. ),
  450. ),
  451. Text(
  452. ' | ',
  453. style: TextStyle(
  454. fontSize: 16.sp,
  455. color: DarkThemeColors.hintTextColor,
  456. ),
  457. ),
  458. GestureDetector(
  459. onTap: controller.handlePaymentIssue,
  460. child: Text(
  461. Strings.paymentIssue.tr,
  462. style: TextStyle(
  463. fontSize: 16.sp,
  464. color: DarkThemeColors.bodyTextColor,
  465. ),
  466. ),
  467. ),
  468. ],
  469. ),
  470. 14.verticalSpaceFromWidth,
  471. Row(
  472. mainAxisAlignment: MainAxisAlignment.center,
  473. children: [
  474. IXImage(
  475. source: Assets.subscriptionGreenShield,
  476. width: 20.w,
  477. height: 20.w,
  478. sourceType: ImageSourceType.asset,
  479. ),
  480. 10.horizontalSpace,
  481. Text(
  482. Strings.yearlyAutoRenewCancelAnytime.tr,
  483. style: TextStyle(
  484. fontSize: 13.sp,
  485. color: DarkThemeColors.hintTextColor,
  486. ),
  487. ),
  488. ],
  489. ),
  490. ],
  491. ),
  492. );
  493. }
  494. }