Explorar el Código

Extract billing questions to a separate widget

vishnukvmd hace 4 años
padre
commit
0c1a5659d7
Se han modificado 2 ficheros con 138 adiciones y 134 borrados
  1. 137 0
      lib/ui/billing_questions_widget.dart
  2. 1 134
      lib/ui/subscription_page.dart

+ 137 - 0
lib/ui/billing_questions_widget.dart

@@ -0,0 +1,137 @@
+import 'dart:convert';
+
+import 'package:flutter/material.dart';
+import 'package:photos/core/network.dart';
+import 'package:photos/ui/expansion_card.dart';
+import 'package:photos/ui/loading_widget.dart';
+
+class BillingQuestionsWidget extends StatelessWidget {
+  const BillingQuestionsWidget({
+    Key key,
+  }) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return FutureBuilder(
+      future: Network.instance
+          .getDio()
+          .get("https://static.ente.io/faq.json")
+          .then((response) {
+        final faqItems = <FaqItem>[];
+        for (final item in response.data as List) {
+          faqItems.add(FaqItem.fromMap(item));
+        }
+        return faqItems;
+      }),
+      builder: (BuildContext context, AsyncSnapshot snapshot) {
+        if (snapshot.hasData) {
+          final faqs = <Widget>[];
+          faqs.add(Padding(
+            padding: const EdgeInsets.all(24),
+            child: Text(
+              "faqs",
+              style: TextStyle(
+                fontSize: 18,
+                fontWeight: FontWeight.bold,
+              ),
+            ),
+          ));
+          for (final faq in snapshot.data) {
+            faqs.add(FaqWidget(faq: faq));
+          }
+          faqs.add(Padding(
+            padding: EdgeInsets.all(16),
+          ));
+          return SingleChildScrollView(
+            child: Column(
+              children: faqs,
+            ),
+          );
+        } else {
+          return loadWidget;
+        }
+      },
+    );
+  }
+}
+
+class FaqWidget extends StatelessWidget {
+  const FaqWidget({
+    Key key,
+    @required this.faq,
+  }) : super(key: key);
+
+  final FaqItem faq;
+
+  @override
+  Widget build(BuildContext context) {
+    return ExpansionCard(
+      title: Text(faq.q),
+      color: Theme.of(context).buttonColor,
+      children: [
+        Padding(
+          padding: const EdgeInsets.only(left: 16, right: 16),
+          child: Text(
+            faq.a,
+            style: TextStyle(
+              height: 1.5,
+            ),
+          ),
+        )
+      ],
+    );
+  }
+}
+
+class FaqItem {
+  final String q;
+  final String a;
+  FaqItem({
+    this.q,
+    this.a,
+  });
+
+  FaqItem copyWith({
+    String q,
+    String a,
+  }) {
+    return FaqItem(
+      q: q ?? this.q,
+      a: a ?? this.a,
+    );
+  }
+
+  Map<String, dynamic> toMap() {
+    return {
+      'q': q,
+      'a': a,
+    };
+  }
+
+  factory FaqItem.fromMap(Map<String, dynamic> map) {
+    if (map == null) return null;
+
+    return FaqItem(
+      q: map['q'],
+      a: map['a'],
+    );
+  }
+
+  String toJson() => json.encode(toMap());
+
+  factory FaqItem.fromJson(String source) =>
+      FaqItem.fromMap(json.decode(source));
+
+  @override
+  String toString() => 'FaqItem(q: $q, a: $a)';
+
+  @override
+  bool operator ==(Object o) {
+    if (identical(this, o)) return true;
+
+    return o is FaqItem && o.q == q && o.a == a;
+  }
+
+  @override
+  int get hashCode => q.hashCode ^ a.hashCode;
+}

+ 1 - 134
lib/ui/subscription_page.dart

@@ -1,5 +1,4 @@
 import 'dart:async';
-import 'dart:convert';
 import 'dart:io';
 
 import 'package:flutter/cupertino.dart';
@@ -8,13 +7,12 @@ import 'package:flutter/widgets.dart';
 import 'package:in_app_purchase/in_app_purchase.dart';
 import 'package:logging/logging.dart';
 import 'package:photos/core/event_bus.dart';
-import 'package:photos/core/network.dart';
 import 'package:photos/events/subscription_purchased_event.dart';
 import 'package:photos/models/billing_plan.dart';
 import 'package:photos/models/subscription.dart';
 import 'package:photos/services/billing_service.dart';
+import 'package:photos/ui/billing_questions_widget.dart';
 import 'package:photos/ui/common_elements.dart';
-import 'package:photos/ui/expansion_card.dart';
 import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/ui/progress_dialog.dart';
 import 'package:photos/utils/data_util.dart';
@@ -455,137 +453,6 @@ class _SubscriptionPageState extends State<SubscriptionPage> {
   }
 }
 
-class BillingQuestionsWidget extends StatelessWidget {
-  const BillingQuestionsWidget({
-    Key key,
-  }) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    return FutureBuilder(
-      future: Network.instance
-          .getDio()
-          .get("https://static.ente.io/faq.json")
-          .then((response) {
-        final faqItems = <FaqItem>[];
-        for (final item in response.data as List) {
-          faqItems.add(FaqItem.fromMap(item));
-        }
-        return faqItems;
-      }),
-      builder: (BuildContext context, AsyncSnapshot snapshot) {
-        if (snapshot.hasData) {
-          final faqs = <Widget>[];
-          faqs.add(Padding(
-            padding: const EdgeInsets.all(24),
-            child: Text(
-              "faqs",
-              style: TextStyle(
-                fontSize: 18,
-                fontWeight: FontWeight.bold,
-              ),
-            ),
-          ));
-          for (final faq in snapshot.data) {
-            faqs.add(FaqWidget(faq: faq));
-          }
-          faqs.add(Padding(
-            padding: EdgeInsets.all(16),
-          ));
-          return SingleChildScrollView(
-            child: Column(
-              children: faqs,
-            ),
-          );
-        } else {
-          return loadWidget;
-        }
-      },
-    );
-  }
-}
-
-class FaqWidget extends StatelessWidget {
-  const FaqWidget({
-    Key key,
-    @required this.faq,
-  }) : super(key: key);
-
-  final FaqItem faq;
-
-  @override
-  Widget build(BuildContext context) {
-    return ExpansionCard(
-      title: Text(faq.q),
-      color: Theme.of(context).buttonColor,
-      children: [
-        Padding(
-          padding: const EdgeInsets.only(left: 16, right: 16),
-          child: Text(
-            faq.a,
-            style: TextStyle(
-              height: 1.5,
-            ),
-          ),
-        )
-      ],
-    );
-  }
-}
-
-class FaqItem {
-  final String q;
-  final String a;
-  FaqItem({
-    this.q,
-    this.a,
-  });
-
-  FaqItem copyWith({
-    String q,
-    String a,
-  }) {
-    return FaqItem(
-      q: q ?? this.q,
-      a: a ?? this.a,
-    );
-  }
-
-  Map<String, dynamic> toMap() {
-    return {
-      'q': q,
-      'a': a,
-    };
-  }
-
-  factory FaqItem.fromMap(Map<String, dynamic> map) {
-    if (map == null) return null;
-
-    return FaqItem(
-      q: map['q'],
-      a: map['a'],
-    );
-  }
-
-  String toJson() => json.encode(toMap());
-
-  factory FaqItem.fromJson(String source) =>
-      FaqItem.fromMap(json.decode(source));
-
-  @override
-  String toString() => 'FaqItem(q: $q, a: $a)';
-
-  @override
-  bool operator ==(Object o) {
-    if (identical(this, o)) return true;
-
-    return o is FaqItem && o.q == q && o.a == a;
-  }
-
-  @override
-  int get hashCode => q.hashCode ^ a.hashCode;
-}
-
 class SubscriptionPlanWidget extends StatelessWidget {
   const SubscriptionPlanWidget({
     Key key,