subscription_view.dart 18 KB

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