subscription_view.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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. // 仅 userLevel == 3 时显示套餐变更信息
  76. if (controller.showPlanChangeInfo)
  77. _buildPlanChangeInfo(),
  78. 16.verticalSpaceFromWidth,
  79. _buildPremiumFeatures(),
  80. 16.verticalSpaceFromWidth,
  81. ],
  82. ),
  83. ),
  84. ),
  85. _buildBottomSection(),
  86. ],
  87. ),
  88. ),
  89. ],
  90. ),
  91. );
  92. }
  93. // 顶部标题栏
  94. Widget _buildAppBar() {
  95. return Padding(
  96. padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 12.h),
  97. child: Row(
  98. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  99. children: [
  100. SizedBox(width: 32.w),
  101. Text(
  102. Strings.subscription.tr,
  103. style: TextStyle(
  104. fontSize: 16.sp,
  105. height: 1.4,
  106. fontWeight: FontWeight.w500,
  107. color: Colors.white,
  108. ),
  109. ),
  110. GestureDetector(
  111. onTap: () => Get.back(),
  112. child: Container(
  113. width: 24.w,
  114. height: 24.w,
  115. decoration: BoxDecoration(
  116. color: Colors.white.withValues(alpha: 0.1),
  117. shape: BoxShape.circle,
  118. ),
  119. child: Icon(Icons.close_rounded, color: Colors.white, size: 16.w),
  120. ),
  121. ),
  122. ],
  123. ),
  124. );
  125. }
  126. // 当前订阅信息
  127. Widget _buildCurrentSubscription() {
  128. return Row(
  129. mainAxisAlignment: MainAxisAlignment.center,
  130. children: [
  131. // 钻石图标
  132. IXImage(
  133. source: Assets.subscriptionDiamond,
  134. width: 92.w,
  135. height: 80.w,
  136. sourceType: ImageSourceType.asset,
  137. ),
  138. 12.horizontalSpace,
  139. Expanded(
  140. child: Column(
  141. crossAxisAlignment: CrossAxisAlignment.start,
  142. children: [
  143. Row(
  144. children: [
  145. IXImage(
  146. source: Assets.subscriptionWallet,
  147. width: 20.w,
  148. height: 20.w,
  149. sourceType: ImageSourceType.asset,
  150. ),
  151. 4.horizontalSpace,
  152. Text(
  153. Strings.currentSubscription.tr,
  154. style: TextStyle(
  155. fontSize: 14.sp,
  156. height: 1.4,
  157. color: DarkThemeColors.subscriptionColor,
  158. fontWeight: FontWeight.w700,
  159. ),
  160. ),
  161. ],
  162. ),
  163. 10.verticalSpaceFromWidth,
  164. Text(
  165. Strings.yearPlanPrice.trParams({'price': '\$40.00'}),
  166. style: TextStyle(
  167. fontSize: 14.sp,
  168. height: 1.4,
  169. color: Colors.white,
  170. ),
  171. ),
  172. ],
  173. ),
  174. ),
  175. ],
  176. );
  177. }
  178. // 订阅计划选项
  179. Widget _buildPlanOptions() {
  180. return Obx(() {
  181. // 加载中状态
  182. if (controller.isLoadingPlans.value) {
  183. return Padding(
  184. padding: EdgeInsets.symmetric(vertical: 40.w),
  185. child: Center(
  186. child: CircularProgressIndicator(
  187. color: DarkThemeColors.subscriptionColor,
  188. ),
  189. ),
  190. );
  191. }
  192. // 空数据状态
  193. if (controller.planCount == 0) {
  194. return Padding(
  195. padding: EdgeInsets.symmetric(vertical: 40.w),
  196. child: Center(
  197. child: Text(
  198. '暂无可用套餐',
  199. style: TextStyle(
  200. fontSize: 14.sp,
  201. color: DarkThemeColors.hintTextColor,
  202. ),
  203. ),
  204. ),
  205. );
  206. }
  207. // 套餐列表
  208. return Column(
  209. children: List.generate(
  210. controller.planCount,
  211. (index) => _buildPlanItem(index),
  212. ),
  213. );
  214. });
  215. }
  216. Widget _buildPlanItem(int index) {
  217. return Obx(() {
  218. final isSelected = controller.selectedPlanIndex.value == index;
  219. final badge = controller.getPlanBadge(index);
  220. final badgeBgColor = controller.getPlanBadgeBgColor(index);
  221. final badgeTextColor = controller.getPlanBadgeTextColor(index);
  222. final badgeBorderColor = controller.getPlanBadgeBorderColor(index);
  223. return GestureDetector(
  224. onTap: () => controller.selectPlan(index),
  225. child: Container(
  226. margin: EdgeInsets.only(bottom: 18.w),
  227. decoration: BoxDecoration(
  228. color: DarkThemeColors.cardColor,
  229. borderRadius: BorderRadius.circular(12.r),
  230. border: Border.all(
  231. color: isSelected
  232. ? DarkThemeColors.subscriptionColor
  233. : DarkThemeColors.dividerColor,
  234. width: 2.w,
  235. ),
  236. ),
  237. child: Stack(
  238. clipBehavior: Clip.none,
  239. children: [
  240. // 主要内容
  241. Padding(
  242. padding: EdgeInsets.all(10.w),
  243. child: Row(
  244. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  245. children: [
  246. // 左侧:价格信息
  247. Expanded(
  248. child: Column(
  249. crossAxisAlignment: CrossAxisAlignment.start,
  250. children: [
  251. Text(
  252. controller.getPlanTitle(index),
  253. style: TextStyle(
  254. fontSize: 18.sp,
  255. height: 1.4,
  256. color: DarkThemeColors.bodyTextColor,
  257. fontWeight: FontWeight.w600,
  258. ),
  259. ),
  260. Text(
  261. controller.getPlanSubTitle(index),
  262. style: TextStyle(
  263. fontSize: 12.sp,
  264. height: 1.6,
  265. color: DarkThemeColors.hintTextColor,
  266. ),
  267. ),
  268. ],
  269. ),
  270. ),
  271. // 右侧:标题和选择框
  272. Row(
  273. children: [
  274. Text(
  275. controller.getPlanIntroduce(index),
  276. style: TextStyle(
  277. fontSize: 13.sp,
  278. height: 1.4,
  279. color: DarkThemeColors.bodyTextColor,
  280. ),
  281. ),
  282. 8.horizontalSpace,
  283. Container(
  284. width: 20.w,
  285. height: 20.w,
  286. decoration: BoxDecoration(
  287. shape: BoxShape.circle,
  288. border: Border.all(
  289. color: isSelected
  290. ? DarkThemeColors.primaryColor
  291. : Colors.white30,
  292. width: 1.5.w,
  293. ),
  294. color: isSelected
  295. ? DarkThemeColors.primaryColor
  296. : Colors.transparent,
  297. ),
  298. child: isSelected
  299. ? Icon(
  300. Icons.check,
  301. color: Colors.white,
  302. size: 12.w,
  303. )
  304. : null,
  305. ),
  306. ],
  307. ),
  308. ],
  309. ),
  310. ),
  311. // 标签固定在右上角,压在边框线上
  312. if (badge.isNotEmpty)
  313. Positioned(
  314. top: -11.h,
  315. right: 12.w,
  316. child: Container(
  317. padding: EdgeInsets.symmetric(horizontal: 6.w),
  318. decoration: BoxDecoration(
  319. color: badgeBgColor ?? Colors.black,
  320. borderRadius: BorderRadius.circular(4.r),
  321. border: badgeBorderColor != null
  322. ? Border.all(color: badgeBorderColor, width: 1)
  323. : null,
  324. ),
  325. child: Text(
  326. badge,
  327. style: TextStyle(
  328. fontSize: 12.sp,
  329. color: badgeTextColor ?? Colors.white,
  330. height: 1.6,
  331. ),
  332. ),
  333. ),
  334. ),
  335. ],
  336. ),
  337. ),
  338. );
  339. });
  340. }
  341. // 计划变更信息
  342. Widget _buildPlanChangeInfo() {
  343. return InfoCard(
  344. title: Strings.planChangeInfo.tr,
  345. items: [
  346. InfoItem(
  347. imageSource: Assets.subscriptionPlanChange1,
  348. title: Strings.whenItStarts.tr,
  349. description: Strings.yourNewPlanBeginsRightAway.tr,
  350. iconColor: DarkThemeColors.primaryColor,
  351. ),
  352. InfoItem(
  353. imageSource: Assets.subscriptionPlanChange2,
  354. title: Strings.whatHappensToYourBalance.tr,
  355. description: Strings.anyUnusedAmountFromYourOldPlan.tr,
  356. iconColor: DarkThemeColors.primaryColor,
  357. ),
  358. InfoItem(
  359. imageSource: Assets.subscriptionPlanChange3,
  360. title: Strings.extraTime.tr,
  361. description: Strings.youllGetExtraDays.tr,
  362. iconColor: DarkThemeColors.primaryColor,
  363. ),
  364. ],
  365. );
  366. }
  367. // Premium 功能列表
  368. Widget _buildPremiumFeatures() {
  369. return Column(
  370. crossAxisAlignment: CrossAxisAlignment.start,
  371. children: [
  372. Text(
  373. Strings.premiumsIncluded.tr,
  374. style: TextStyle(
  375. fontSize: 16.sp,
  376. color: DarkThemeColors.subscriptionColor,
  377. fontWeight: FontWeight.w500,
  378. ),
  379. ),
  380. 16.verticalSpace,
  381. Container(
  382. padding: EdgeInsets.symmetric(vertical: 4.w, horizontal: 10.w),
  383. decoration: BoxDecoration(
  384. color: DarkThemeColors.bgDisable,
  385. borderRadius: BorderRadius.circular(12.r),
  386. ),
  387. child: Column(
  388. children: [
  389. _buildFeatureItem(
  390. IconFont.icon60,
  391. Strings.unlockAllFreeLocations.tr,
  392. ),
  393. _buildFeatureItem(IconFont.icon61, Strings.unlockSmartMode.tr),
  394. _buildFeatureItem(IconFont.icon62, Strings.unlockMultiHopMode.tr),
  395. Obx(
  396. () => _buildFeatureItem(
  397. IconFont.icon63,
  398. Strings.premiumCanShareXDevices.trParams({
  399. 'count': controller.selectedPlanDeviceLimit,
  400. }),
  401. ),
  402. ),
  403. _buildFeatureItem(
  404. IconFont.icon64,
  405. Strings.ownYourOwnPrivateServer.tr,
  406. ),
  407. _buildFeatureItem(IconFont.icon65, Strings.closeAds.tr),
  408. ],
  409. ),
  410. ),
  411. ],
  412. );
  413. }
  414. Widget _buildFeatureItem(IconData icon, String title) {
  415. return SizedBox(
  416. height: 44.w,
  417. child: Row(
  418. children: [
  419. Icon(icon, color: DarkThemeColors.subscriptionColor, size: 24.w),
  420. 12.horizontalSpace,
  421. Expanded(
  422. child: Text(
  423. title,
  424. style: TextStyle(
  425. fontSize: 13.sp,
  426. color: Get.reactiveTheme.hintColor,
  427. ),
  428. ),
  429. ),
  430. Container(
  431. width: 20.w,
  432. height: 20.w,
  433. decoration: BoxDecoration(
  434. shape: BoxShape.circle,
  435. color: DarkThemeColors.subscriptionSelectColor,
  436. ),
  437. child: Icon(Icons.check, color: Colors.white, size: 12.w),
  438. ),
  439. ],
  440. ),
  441. );
  442. }
  443. // 底部按钮区域
  444. Widget _buildBottomSection() {
  445. return Container(
  446. padding: EdgeInsets.symmetric(vertical: 10.w, horizontal: 14.w),
  447. decoration: BoxDecoration(
  448. border: Border(
  449. top: BorderSide(color: Colors.white.withOpacity(0.1), width: 1),
  450. ),
  451. ),
  452. child: Column(
  453. mainAxisSize: MainAxisSize.min,
  454. children: [
  455. // 确认按钮
  456. GestureDetector(
  457. onTap: controller.subscribe,
  458. child: Container(
  459. width: double.infinity,
  460. height: 48.w,
  461. decoration: BoxDecoration(
  462. color: DarkThemeColors.backgroundColor,
  463. borderRadius: BorderRadius.circular(12.r),
  464. ),
  465. child: Center(
  466. child: Text(
  467. controller.showPlanChangeInfo
  468. ? Strings.confirmChange.tr
  469. : Strings.subscription.tr,
  470. style: TextStyle(
  471. fontSize: 16.sp,
  472. color: DarkThemeColors.subscriptionColor,
  473. fontWeight: FontWeight.w600,
  474. ),
  475. ),
  476. ),
  477. ),
  478. ),
  479. 14.verticalSpaceFromWidth,
  480. // 底部链接
  481. Row(
  482. mainAxisAlignment: MainAxisAlignment.center,
  483. children: [
  484. GestureDetector(
  485. onTap: controller.restorePurchases,
  486. child: Text(
  487. Strings.restorePurchases.tr,
  488. style: TextStyle(
  489. fontSize: 16.sp,
  490. color: DarkThemeColors.bodyTextColor,
  491. ),
  492. ),
  493. ),
  494. Text(
  495. ' | ',
  496. style: TextStyle(
  497. fontSize: 16.sp,
  498. color: DarkThemeColors.hintTextColor,
  499. ),
  500. ),
  501. GestureDetector(
  502. onTap: controller.handlePaymentIssue,
  503. child: Text(
  504. Strings.paymentIssue.tr,
  505. style: TextStyle(
  506. fontSize: 16.sp,
  507. color: DarkThemeColors.bodyTextColor,
  508. ),
  509. ),
  510. ),
  511. ],
  512. ),
  513. 14.verticalSpaceFromWidth,
  514. Row(
  515. mainAxisAlignment: MainAxisAlignment.center,
  516. children: [
  517. IXImage(
  518. source: Assets.subscriptionGreenShield,
  519. width: 20.w,
  520. height: 20.w,
  521. sourceType: ImageSourceType.asset,
  522. ),
  523. 10.horizontalSpace,
  524. Text(
  525. Strings.yearlyAutoRenewCancelAnytime.tr,
  526. style: TextStyle(
  527. fontSize: 13.sp,
  528. color: DarkThemeColors.hintTextColor,
  529. ),
  530. ),
  531. ],
  532. ),
  533. ],
  534. ),
  535. );
  536. }
  537. }