فهرست منبع

Fetch the latest subscription status and refresh the header widget if subscription has expired

Vishnu Mohandas 4 سال پیش
والد
کامیت
37472726b0
1فایلهای تغییر یافته به همراه20 افزوده شده و 0 حذف شده
  1. 20 0
      lib/ui/sign_in_header_widget.dart

+ 20 - 0
lib/ui/sign_in_header_widget.dart

@@ -43,7 +43,26 @@ class _SignInHeaderState extends State<SignInHeader> {
     var hasSubscribed = BillingService.instance.hasActiveSubscription();
     var hasSubscribed = BillingService.instance.hasActiveSubscription();
     if (hasConfiguredAccount && hasSubscribed) {
     if (hasConfiguredAccount && hasSubscribed) {
       return Container();
       return Container();
+    } else if (!hasConfiguredAccount) {
+      return _getBody(context);
+    } else {
+      return FutureBuilder(
+        future: BillingService.instance.fetchSubscription(),
+        builder: (BuildContext context, AsyncSnapshot snapshot) {
+          if (snapshot.hasData) {
+            if (BillingService.instance.hasActiveSubscription()) {
+              return Container();
+            }
+            return _getBody(context);
+          } else {
+            return Container();
+          }
+        },
+      );
     }
     }
+  }
+
+  SingleChildScrollView _getBody(BuildContext context) {
     return SingleChildScrollView(
     return SingleChildScrollView(
       child: Container(
       child: Container(
         padding: EdgeInsets.fromLTRB(8, 24, 8, 8),
         padding: EdgeInsets.fromLTRB(8, 24, 8, 8),
@@ -179,6 +198,7 @@ class _SignInHeaderState extends State<SignInHeader> {
                       // Yet to decrypt the key
                       // Yet to decrypt the key
                       page = PasswordReentryPage();
                       page = PasswordReentryPage();
                     } else {
                     } else {
+                      // All is well, user just has not subscribed
                       page = SubscriptionPage();
                       page = SubscriptionPage();
                     }
                     }
                   }
                   }