Quellcode durchsuchen

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

Vishnu Mohandas vor 4 Jahren
Ursprung
Commit
37472726b0
1 geänderte Dateien mit 20 neuen und 0 gelöschten Zeilen
  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();
     if (hasConfiguredAccount && hasSubscribed) {
       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(
       child: Container(
         padding: EdgeInsets.fromLTRB(8, 24, 8, 8),
@@ -179,6 +198,7 @@ class _SignInHeaderState extends State<SignInHeader> {
                       // Yet to decrypt the key
                       page = PasswordReentryPage();
                     } else {
+                      // All is well, user just has not subscribed
                       page = SubscriptionPage();
                     }
                   }