billing_questions_widget.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import 'dart:convert';
  2. import 'package:expansion_tile_card/expansion_tile_card.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:photos/core/network.dart';
  5. import 'package:photos/ui/loading_widget.dart';
  6. class BillingQuestionsWidget extends StatelessWidget {
  7. const BillingQuestionsWidget({
  8. Key key,
  9. }) : super(key: key);
  10. @override
  11. Widget build(BuildContext context) {
  12. return FutureBuilder(
  13. future: Network.instance
  14. .getDio()
  15. .get("https://static.ente.io/faq.json")
  16. .then((response) {
  17. final faqItems = <FaqItem>[];
  18. for (final item in response.data as List) {
  19. faqItems.add(FaqItem.fromMap(item));
  20. }
  21. return faqItems;
  22. }),
  23. builder: (BuildContext context, AsyncSnapshot snapshot) {
  24. if (snapshot.hasData) {
  25. final faqs = <Widget>[];
  26. faqs.add(
  27. Padding(
  28. padding: const EdgeInsets.all(24),
  29. child: Text(
  30. "FAQs",
  31. style: TextStyle(
  32. fontSize: 18,
  33. fontWeight: FontWeight.bold,
  34. ),
  35. ),
  36. ),
  37. );
  38. for (final faq in snapshot.data) {
  39. faqs.add(FaqWidget(faq: faq));
  40. }
  41. faqs.add(
  42. Padding(
  43. padding: EdgeInsets.all(16),
  44. ),
  45. );
  46. return SingleChildScrollView(
  47. child: Column(
  48. children: faqs,
  49. ),
  50. );
  51. } else {
  52. return loadWidget;
  53. }
  54. },
  55. );
  56. }
  57. }
  58. class FaqWidget extends StatelessWidget {
  59. const FaqWidget({
  60. Key key,
  61. @required this.faq,
  62. }) : super(key: key);
  63. final FaqItem faq;
  64. @override
  65. Widget build(BuildContext context) {
  66. return ExpansionTileCard(
  67. borderRadius: BorderRadius.all(Radius.circular(0)),
  68. elevation: 0,
  69. title: Text(faq.q),
  70. expandedTextColor: Theme.of(context).buttonColor,
  71. baseColor: Theme.of(context).cardColor,
  72. children: [
  73. Padding(
  74. padding: const EdgeInsets.only(left: 16, right: 16),
  75. child: Text(
  76. faq.a,
  77. style: TextStyle(
  78. height: 1.5,
  79. ),
  80. ),
  81. )
  82. ],
  83. );
  84. }
  85. }
  86. class FaqItem {
  87. final String q;
  88. final String a;
  89. FaqItem({
  90. this.q,
  91. this.a,
  92. });
  93. FaqItem copyWith({
  94. String q,
  95. String a,
  96. }) {
  97. return FaqItem(
  98. q: q ?? this.q,
  99. a: a ?? this.a,
  100. );
  101. }
  102. Map<String, dynamic> toMap() {
  103. return {
  104. 'q': q,
  105. 'a': a,
  106. };
  107. }
  108. factory FaqItem.fromMap(Map<String, dynamic> map) {
  109. if (map == null) return null;
  110. return FaqItem(
  111. q: map['q'],
  112. a: map['a'],
  113. );
  114. }
  115. String toJson() => json.encode(toMap());
  116. factory FaqItem.fromJson(String source) =>
  117. FaqItem.fromMap(json.decode(source));
  118. @override
  119. String toString() => 'FaqItem(q: $q, a: $a)';
  120. @override
  121. bool operator ==(Object o) {
  122. if (identical(this, o)) return true;
  123. return o is FaqItem && o.q == q && o.a == a;
  124. }
  125. @override
  126. int get hashCode => q.hashCode ^ a.hashCode;
  127. }