sign_in_header_widget.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/widgets.dart';
  4. import 'package:photos/core/configuration.dart';
  5. import 'package:photos/core/event_bus.dart';
  6. import 'package:photos/events/user_authenticated_event.dart';
  7. import 'package:photos/services/billing_service.dart';
  8. import 'package:photos/ui/email_entry_page.dart';
  9. import 'package:photos/ui/password_entry_page.dart';
  10. import 'package:photos/ui/password_reentry_page.dart';
  11. import 'package:expansion_card/expansion_card.dart';
  12. import 'package:photos/ui/subscription_page.dart';
  13. class SignInHeader extends StatefulWidget {
  14. const SignInHeader({Key key}) : super(key: key);
  15. @override
  16. _SignInHeaderState createState() => _SignInHeaderState();
  17. }
  18. class _SignInHeaderState extends State<SignInHeader> {
  19. StreamSubscription _userAuthEventSubscription;
  20. @override
  21. void initState() {
  22. _userAuthEventSubscription =
  23. Bus.instance.on<UserAuthenticatedEvent>().listen((event) {
  24. setState(() {});
  25. });
  26. super.initState();
  27. }
  28. @override
  29. void dispose() {
  30. _userAuthEventSubscription.cancel();
  31. super.dispose();
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. var hasConfiguredAccount = Configuration.instance.hasConfiguredAccount();
  36. var hasSubscribed = BillingService.instance.hasActiveSubscription();
  37. if (hasConfiguredAccount && hasSubscribed) {
  38. return Container();
  39. }
  40. return SingleChildScrollView(
  41. child: Container(
  42. padding: EdgeInsets.fromLTRB(8, 24, 8, 8),
  43. child: Column(
  44. children: [
  45. Text.rich(
  46. TextSpan(
  47. children: <TextSpan>[
  48. TextSpan(
  49. text: "with ",
  50. style: TextStyle(
  51. fontSize: 16,
  52. ),
  53. ),
  54. TextSpan(
  55. text: "ente",
  56. style: TextStyle(
  57. fontWeight: FontWeight.bold,
  58. fontFamily: 'Montserrat',
  59. fontSize: 16,
  60. ),
  61. ),
  62. ],
  63. ),
  64. textAlign: TextAlign.center,
  65. ),
  66. Padding(
  67. padding: EdgeInsets.all(2),
  68. ),
  69. Text.rich(
  70. TextSpan(
  71. children: <TextSpan>[
  72. TextSpan(
  73. text: "your ",
  74. style: TextStyle(
  75. fontSize: 16,
  76. ),
  77. ),
  78. TextSpan(
  79. text: "memories",
  80. style: TextStyle(
  81. fontWeight: FontWeight.bold,
  82. fontSize: 16,
  83. ),
  84. ),
  85. TextSpan(
  86. text: " are",
  87. style: TextStyle(
  88. fontSize: 16,
  89. ),
  90. ),
  91. ],
  92. ),
  93. textAlign: TextAlign.center,
  94. ),
  95. Padding(
  96. padding: EdgeInsets.all(8),
  97. ),
  98. ExpansionCard(
  99. title: Text('protected'),
  100. margin: EdgeInsets.all(0),
  101. children: <Widget>[
  102. Align(
  103. alignment: Alignment.bottomLeft,
  104. child: Padding(
  105. padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  106. child: Text(
  107. 'only visible to you as they are encrypted by your master key',
  108. ),
  109. ),
  110. ),
  111. ],
  112. ),
  113. ExpansionCard(
  114. title: Text('preserved'),
  115. margin: EdgeInsets.all(0),
  116. children: <Widget>[
  117. Align(
  118. alignment: Alignment.bottomLeft,
  119. child: Padding(
  120. padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  121. child: Text(
  122. 'stored in multiple locations including an underground fallout shelter',
  123. ),
  124. ),
  125. ),
  126. ],
  127. ),
  128. ExpansionCard(
  129. title: Text('accessible'),
  130. margin: EdgeInsets.all(0),
  131. children: <Widget>[
  132. Align(
  133. alignment: Alignment.bottomLeft,
  134. child: Padding(
  135. padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  136. child: Text(
  137. 'available on all your devices',
  138. ),
  139. ),
  140. ),
  141. ],
  142. ),
  143. Padding(
  144. padding: EdgeInsets.all(10),
  145. ),
  146. Padding(
  147. padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
  148. ),
  149. Container(
  150. width: double.infinity,
  151. height: 64,
  152. padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
  153. child: RaisedButton(
  154. child: Text(
  155. "subscribe",
  156. style: TextStyle(
  157. fontWeight: FontWeight.bold,
  158. fontSize: 18,
  159. ),
  160. textAlign: TextAlign.center,
  161. ),
  162. onPressed: () {
  163. var page;
  164. if (Configuration.instance.getToken() == null) {
  165. page = EmailEntryPage();
  166. } else {
  167. // No key
  168. if (Configuration.instance.getKeyAttributes() == null) {
  169. // Never had a key
  170. page = PasswordEntryPage();
  171. } else if (Configuration.instance.getKey() == null) {
  172. // Yet to decrypt the key
  173. page = PasswordReentryPage();
  174. } else {
  175. page = SubscriptionPage();
  176. }
  177. }
  178. Navigator.of(context).push(
  179. MaterialPageRoute(
  180. builder: (BuildContext context) {
  181. return page;
  182. },
  183. ),
  184. );
  185. },
  186. shape: RoundedRectangleBorder(
  187. borderRadius: BorderRadius.circular(10.0),
  188. ),
  189. ),
  190. ),
  191. Padding(padding: EdgeInsets.all(10)),
  192. Divider(
  193. height: 2,
  194. ),
  195. ],
  196. ),
  197. ),
  198. );
  199. }
  200. }