subscription_controller.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:video_player/video_player.dart';
  4. import '../../../../config/theme/dark_theme_colors.dart';
  5. import '../../../components/ix_snackbar.dart';
  6. import '../../../constants/assets.dart';
  7. class SubscriptionController extends GetxController {
  8. // 视频播放器控制器
  9. late VideoPlayerController videoController;
  10. final isVideoInitialized = false.obs;
  11. // 当前选中的订阅计划索引 (0: 年度, 1: 终身, 2: 月度, 3: 周度)
  12. final selectedPlanIndex = 0.obs;
  13. // 订阅计划列表
  14. final List<Map<String, dynamic>> plans = [
  15. {
  16. 'price': '\$40.00',
  17. 'period': 'Per year',
  18. 'title': 'Yearly Plan',
  19. 'badge': 'Mostly choose',
  20. 'badgeBgColor': DarkThemeColors.bg1,
  21. 'badgeTextColor': DarkThemeColors.subscriptionColor,
  22. 'badgeBorderColor': DarkThemeColors.dividerColor, // null 表示没有边框
  23. },
  24. {'price': '\$58.00', 'period': 'once', 'title': 'Life time', 'badge': null},
  25. {'price': '\$58.00', 'period': 'Per', 'title': 'Month Plan', 'badge': null},
  26. {
  27. 'price': '\$1.00',
  28. 'period': 'Per week',
  29. 'title': 'Week Plan',
  30. 'badge': 'Limited Time',
  31. 'badgeBgColor': DarkThemeColors.primaryColor,
  32. 'badgeTextColor': Colors.white,
  33. 'badgeBorderColor': null,
  34. },
  35. ];
  36. @override
  37. void onInit() {
  38. super.onInit();
  39. _initializeVideoPlayer();
  40. }
  41. @override
  42. void onClose() {
  43. videoController.dispose();
  44. super.onClose();
  45. }
  46. // 初始化视频播放器
  47. void _initializeVideoPlayer() {
  48. videoController = VideoPlayerController.asset(Assets.subscriptionBg)
  49. ..initialize()
  50. .then((_) {
  51. isVideoInitialized.value = true;
  52. videoController.setLooping(true);
  53. videoController.setVolume(0); // 静音播放
  54. videoController.play();
  55. })
  56. .catchError((error) {
  57. print('视频初始化失败: $error');
  58. });
  59. }
  60. // 选择订阅计划
  61. void selectPlan(int index) {
  62. selectedPlanIndex.value = index;
  63. }
  64. // 确认变更
  65. void confirmChange() {
  66. // TODO: 实现确认订阅变更逻辑
  67. IXSnackBar.showIXSnackBar(
  68. title: 'Success',
  69. message: 'Subscription plan changed successfully',
  70. );
  71. }
  72. // 恢复购买
  73. void restorePurchases() {
  74. // TODO: 实现恢复购买逻辑
  75. IXSnackBar.showIXSnackBar(title: 'Info', message: 'Restoring purchases...');
  76. }
  77. // 支付问题
  78. void handlePaymentIssue() {
  79. // TODO: 实现支付问题处理逻辑
  80. IXSnackBar.showIXSnackBar(
  81. title: 'Info',
  82. message: 'Opening payment support...',
  83. );
  84. }
  85. }