sign_in_header_widget.dart 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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/subscription_purchased_event.dart';
  7. import 'package:photos/services/billing_service.dart';
  8. import 'package:photos/ui/email_entry_page.dart';
  9. import 'package:photos/ui/expansion_card.dart';
  10. import 'package:photos/ui/password_entry_page.dart';
  11. import 'package:photos/ui/password_reentry_page.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<SubscriptionPurchasedEvent>().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 hasSubscription = BillingService.instance.getSubscription() != null;
  37. if (hasConfiguredAccount && hasSubscription) {
  38. return Container();
  39. } else {
  40. return _getBody(context);
  41. }
  42. }
  43. SingleChildScrollView _getBody(BuildContext context) {
  44. return SingleChildScrollView(
  45. child: Container(
  46. padding: EdgeInsets.fromLTRB(8, 24, 8, 8),
  47. child: Column(
  48. children: [
  49. Text.rich(
  50. TextSpan(
  51. children: <TextSpan>[
  52. TextSpan(
  53. text: "with ",
  54. style: TextStyle(
  55. fontSize: 16,
  56. ),
  57. ),
  58. TextSpan(
  59. text: "ente",
  60. style: TextStyle(
  61. fontWeight: FontWeight.bold,
  62. fontFamily: 'Montserrat',
  63. fontSize: 16,
  64. ),
  65. ),
  66. ],
  67. ),
  68. textAlign: TextAlign.center,
  69. ),
  70. Padding(
  71. padding: EdgeInsets.all(2),
  72. ),
  73. Text.rich(
  74. TextSpan(
  75. children: <TextSpan>[
  76. TextSpan(
  77. text: "your ",
  78. style: TextStyle(
  79. fontSize: 16,
  80. ),
  81. ),
  82. TextSpan(
  83. text: "memories",
  84. style: TextStyle(
  85. fontWeight: FontWeight.bold,
  86. fontSize: 16,
  87. ),
  88. ),
  89. TextSpan(
  90. text: " are",
  91. style: TextStyle(
  92. fontSize: 16,
  93. ),
  94. ),
  95. ],
  96. ),
  97. textAlign: TextAlign.center,
  98. ),
  99. Padding(
  100. padding: EdgeInsets.all(8),
  101. ),
  102. ExpansionCard(
  103. title: Text('protected'),
  104. color: Theme.of(context).accentColor,
  105. margin: EdgeInsets.all(0),
  106. children: <Widget>[
  107. Align(
  108. alignment: Alignment.bottomLeft,
  109. child: Padding(
  110. padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  111. child: Text(
  112. 'only visible to you as they are encrypted by your master key',
  113. ),
  114. ),
  115. ),
  116. ],
  117. ),
  118. ExpansionCard(
  119. title: Text('preserved'),
  120. color: Theme.of(context).accentColor,
  121. margin: EdgeInsets.all(0),
  122. children: <Widget>[
  123. Align(
  124. alignment: Alignment.bottomLeft,
  125. child: Padding(
  126. padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  127. child: Text(
  128. 'stored in multiple locations including an underground fallout shelter',
  129. ),
  130. ),
  131. ),
  132. ],
  133. ),
  134. ExpansionCard(
  135. title: Text('accessible'),
  136. color: Theme.of(context).accentColor,
  137. margin: EdgeInsets.all(0),
  138. children: <Widget>[
  139. Align(
  140. alignment: Alignment.bottomLeft,
  141. child: Padding(
  142. padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  143. child: Text(
  144. 'available on all your devices',
  145. ),
  146. ),
  147. ),
  148. ],
  149. ),
  150. Padding(
  151. padding: EdgeInsets.all(10),
  152. ),
  153. Padding(
  154. padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
  155. ),
  156. Container(
  157. width: double.infinity,
  158. height: 64,
  159. padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
  160. child: RaisedButton(
  161. child: Text(
  162. "subscribe",
  163. style: TextStyle(
  164. fontWeight: FontWeight.bold,
  165. fontSize: 18,
  166. letterSpacing: 1.0,
  167. ),
  168. textAlign: TextAlign.center,
  169. ),
  170. onPressed: () {
  171. var page;
  172. if (Configuration.instance.getToken() == null) {
  173. page = EmailEntryPage();
  174. } else {
  175. // No key
  176. if (Configuration.instance.getKeyAttributes() == null) {
  177. // Never had a key
  178. page = PasswordEntryPage();
  179. } else if (Configuration.instance.getKey() == null) {
  180. // Yet to decrypt the key
  181. page = PasswordReentryPage();
  182. } else {
  183. // All is well, user just has not subscribed
  184. page = SubscriptionPage();
  185. }
  186. }
  187. Navigator.of(context).push(
  188. MaterialPageRoute(
  189. builder: (BuildContext context) {
  190. return page;
  191. },
  192. ),
  193. );
  194. },
  195. shape: RoundedRectangleBorder(
  196. borderRadius: BorderRadius.circular(10.0),
  197. ),
  198. ),
  199. ),
  200. Padding(padding: EdgeInsets.all(10)),
  201. Divider(
  202. height: 2,
  203. ),
  204. ],
  205. ),
  206. ),
  207. );
  208. }
  209. }