Destiny 8 mesi fa
parent
commit
0f6b49dc9f
1 ha cambiato i file con 24 aggiunte e 31 eliminazioni
  1. 24 31
      lib/module/store/discount/discount_view.dart

+ 24 - 31
lib/module/store/discount/discount_view.dart

@@ -1,5 +1,4 @@
 import 'dart:async';
-import 'dart:ffi';
 import 'package:intl/intl.dart';
 import 'package:clean/data/bean/store_item.dart';
 import 'package:clean/base/base_page.dart';
@@ -8,7 +7,9 @@ import 'package:clean/utils/expand.dart';
 import 'package:flutter/Material.dart';
 import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'package:get/get.dart';
-
+import 'package:clean/module/browser/browser_view.dart';
+import 'package:collection/collection.dart';
+import 'package:clean/data/consts/constants.dart';
 import '../../../resource/assets.gen.dart';
 import 'count_down_timer.dart';
 import 'func_page_view.dart';
@@ -27,14 +28,9 @@ class DiscountPage extends BasePage<DiscountController> {
   @override
   Widget buildBody(BuildContext context) {
     return Obx(() {
-      bool isFreeItem =
-      (controller.currentSelectedStoreItem.value?.freeTrialName != null);
-      bool isShowFree = isFreeItem && controller.isFree.value;
-
-      bool hasUsedFreeTrial = false;
-      bool canShowFreeTrial = isFreeItem && !hasUsedFreeTrial;
-
-      StoreItem? freeItem = controller.storeItems.firstWhereOrNull((element) => element.freeTrialName != null);
+      bool isSelectFreeItem = controller.currentSelectedStoreItem.value?.freeTrialName != null;
+      // 如果有免费试用,则使用免费试用,否则使用第一个
+      StoreItem? freeItem = controller.storeItems.firstWhereOrNull((element) => element.freeTrialName != null) ?? controller.storeItems.firstOrNull;
       return Scaffold(
         backgroundColor: "#05050D".color,
         body: Stack(
@@ -53,9 +49,7 @@ class DiscountPage extends BasePage<DiscountController> {
                     if (freeItem != null)
                       _DiscountFreeTrialSpecialRow(
                         item: freeItem,
-                        isSelected: canShowFreeTrial,
-                        // canStarFreeTrail: freeItem.freeTrialName != "" && controller.isFree.value,
-                        canStarFreeTrail: true,
+                        isSelected: controller.currentSelectedStoreItem.value?.id == freeItem.id,
                         onSelect: (title) {
                           controller.currentSelectedStoreItem.value = freeItem;
                         },
@@ -65,7 +59,7 @@ class DiscountPage extends BasePage<DiscountController> {
                     SizedBox(height: 40.h),
                     _MorePlansSection(),
                     SizedBox(height: 5.h),
-                    _OtherPlansSection(items: controller.storeItems.where((element) => element.freeTrialName == null).toList(), controller: controller),
+                    _OtherPlansSection(items: controller.storeItems.where((element) => element.id != freeItem?.id).toList(), controller: controller),
                     SizedBox(height: 100.h),
                   ],
                 ),
@@ -77,10 +71,10 @@ class DiscountPage extends BasePage<DiscountController> {
                 mainAxisSize: MainAxisSize.max,
                 children: [
                   Spacer(),
-                  Container(
+                  SizedBox(
                     width: double.infinity,
                     child: _PurchaseSection(
-                      isShowFree: canShowFreeTrial,
+                      isSelectFreeItem: isSelectFreeItem,
                       controller: controller,
                     ),
                   )
@@ -199,12 +193,12 @@ class _FeaturesPreview extends StatelessWidget {
 }
 
 class _PurchaseSection extends StatelessWidget {
-  final bool isShowFree;
+  final bool isSelectFreeItem;
   final DiscountController controller;
 
   const _PurchaseSection({
     Key? key,
-    required this.isShowFree,
+    required this.isSelectFreeItem,
     required this.controller,
   }) : super(key: key);
 
@@ -224,7 +218,7 @@ class _PurchaseSection extends StatelessWidget {
       child: Column(
         children: [
           Text(
-            isShowFree
+            isSelectFreeItem
                 ?  ""
                 : "Auto-renewalable.Cancel anytime",
             style: TextStyle(
@@ -248,7 +242,7 @@ class _PurchaseSection extends StatelessWidget {
               ),
               child: Center(
                 child: Text(
-                  isShowFree ? "START FREE TRIAL" : "Continue",
+                  isSelectFreeItem ? "START FREE TRIAL" : "Continue",
                   style: TextStyle(
                     color: Colors.white,
                     fontWeight: FontWeight.w700,
@@ -259,7 +253,7 @@ class _PurchaseSection extends StatelessWidget {
             ),
           ),
           SizedBox(height: 5.h),
-          isShowFree ?
+          isSelectFreeItem ?
           Text("No payment now!",
             style: TextStyle(
               color: "#57C87A".color,
@@ -276,7 +270,7 @@ class _PurchaseSection extends StatelessWidget {
               children: [
                 GestureDetector(
                   onTap: () {
-                    controller.onBuyClick();
+                    BrowserPage.start(Constants.privacyPolicy);
                   },
                   child: Text("Privacy Policy", style: TextStyle(color: Colors.white.withOpacity(0.8), fontSize: 12.sp, fontWeight: FontWeight.w400)),
                 ),
@@ -285,9 +279,9 @@ class _PurchaseSection extends StatelessWidget {
                 SizedBox(width: 8.w),
                 GestureDetector(
                   onTap: () {
-                    controller.onBuyClick();
+                    BrowserPage.start(Constants.userAgreement);
                   },
-                  child: Text("Privacy Policy", style: TextStyle(color: Colors.white.withOpacity(0.8), fontSize: 12.sp, fontWeight: FontWeight.w400)),
+                  child: Text("Terms of Service", style: TextStyle(color: Colors.white.withOpacity(0.8), fontSize: 12.sp, fontWeight: FontWeight.w400)),
                 ),
               ],
             ),
@@ -334,12 +328,11 @@ class _OtherPlansSection extends StatelessWidget {
           child: _DiscountFreeTrialSpecialRow(
             item: item,
             isSelected: controller.currentSelectedStoreItem.value?.id == item.id,
-            canStarFreeTrail: item.freeTrialName != null && controller.isFree.value,
             onSelect: (item) {
               controller.currentSelectedStoreItem.value = item;
             },
           ),
-        )).toList(),
+        )),
       ],
     );
   }
@@ -348,10 +341,13 @@ class _OtherPlansSection extends StatelessWidget {
 class _DiscountFreeTrialSpecialRow extends StatelessWidget {
   final StoreItem item;
   final bool isSelected;
-  final bool canStarFreeTrail;
   final Function(StoreItem) onSelect;
 
-  const _DiscountFreeTrialSpecialRow({Key? key, required this.item, required this.isSelected, required this.canStarFreeTrail, required this.onSelect}) : super(key: key);
+  bool get canStarFreeTrail {
+    return item.freeTrialName != null;
+  }
+
+  const _DiscountFreeTrialSpecialRow({Key? key, required this.item, required this.isSelected, required this.onSelect}) : super(key: key);
 
   @override
   Widget build(BuildContext context) {
@@ -536,6 +532,3 @@ class _DiscountFreeTrialSpecialRow extends StatelessWidget {
     );
   }
 }
-
-
-