sign_in_header_widget.dart 6.3 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/ui/common_elements.dart';
  8. import 'package:photos/ui/email_entry_page.dart';
  9. import 'package:photos/ui/passphrase_entry_page.dart';
  10. import 'package:photos/ui/passphrase_reentry_page.dart';
  11. import 'package:expansion_card/expansion_card.dart';
  12. class SignInHeader extends StatefulWidget {
  13. const SignInHeader({Key key}) : super(key: key);
  14. @override
  15. _SignInHeaderState createState() => _SignInHeaderState();
  16. }
  17. class _SignInHeaderState extends State<SignInHeader> {
  18. StreamSubscription _userAuthEventSubscription;
  19. @override
  20. void initState() {
  21. _userAuthEventSubscription =
  22. Bus.instance.on<UserAuthenticatedEvent>().listen((event) {
  23. setState(() {});
  24. });
  25. super.initState();
  26. }
  27. @override
  28. void dispose() {
  29. _userAuthEventSubscription.cancel();
  30. super.dispose();
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. if (Configuration.instance.hasConfiguredAccount()) {
  35. return Container();
  36. }
  37. return SingleChildScrollView(
  38. child: Container(
  39. padding: EdgeInsets.all(8),
  40. child: Column(
  41. children: [
  42. Text.rich(
  43. TextSpan(
  44. children: <TextSpan>[
  45. TextSpan(
  46. text: "with ",
  47. style: TextStyle(
  48. fontSize: 16,
  49. ),
  50. ),
  51. TextSpan(
  52. text: "ente",
  53. style: TextStyle(
  54. fontWeight: FontWeight.bold,
  55. fontFamily: 'Montserrat',
  56. fontSize: 16,
  57. ),
  58. ),
  59. ],
  60. ),
  61. textAlign: TextAlign.center,
  62. ),
  63. Padding(
  64. padding: EdgeInsets.all(6),
  65. ),
  66. Text.rich(
  67. TextSpan(
  68. children: <TextSpan>[
  69. TextSpan(
  70. text: "your ",
  71. style: TextStyle(
  72. fontSize: 16,
  73. ),
  74. ),
  75. TextSpan(
  76. text: "memories",
  77. style: TextStyle(
  78. fontWeight: FontWeight.bold,
  79. fontSize: 16,
  80. ),
  81. ),
  82. TextSpan(
  83. text: " are",
  84. style: TextStyle(
  85. fontSize: 16,
  86. ),
  87. ),
  88. ],
  89. ),
  90. textAlign: TextAlign.center,
  91. ),
  92. Padding(
  93. padding: EdgeInsets.all(10),
  94. ),
  95. ExpansionCard(
  96. title: Text('protected'),
  97. margin: EdgeInsets.all(0),
  98. children: <Widget>[
  99. Align(
  100. alignment: Alignment.bottomLeft,
  101. child: Padding(
  102. padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  103. child: Text(
  104. 'only visible to you as they are encrypted by your master key',
  105. ),
  106. ),
  107. ),
  108. ],
  109. ),
  110. ExpansionCard(
  111. title: Text('preserved'),
  112. margin: EdgeInsets.all(0),
  113. children: <Widget>[
  114. Align(
  115. alignment: Alignment.bottomLeft,
  116. child: Padding(
  117. padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  118. child: Text(
  119. 'stored in multiple locations including an underground fallout shelter',
  120. ),
  121. ),
  122. ),
  123. ],
  124. ),
  125. ExpansionCard(
  126. title: Text('accessible'),
  127. margin: EdgeInsets.all(0),
  128. children: <Widget>[
  129. Align(
  130. alignment: Alignment.bottomLeft,
  131. child: Padding(
  132. padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
  133. child: Text(
  134. 'available on all your devices',
  135. ),
  136. ),
  137. ),
  138. ],
  139. ),
  140. Padding(
  141. padding: EdgeInsets.all(10),
  142. ),
  143. Padding(
  144. padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
  145. ),
  146. Container(
  147. width: double.infinity,
  148. height: 64,
  149. child: RaisedButton(
  150. child: Hero(
  151. tag: "sign_up_hero_text",
  152. child: Material(
  153. color: Colors.transparent,
  154. child: Text(
  155. "sign up",
  156. style: TextStyle(
  157. fontWeight: FontWeight.bold,
  158. fontSize: 18,
  159. ),
  160. textAlign: TextAlign.center,
  161. ),
  162. ),
  163. ),
  164. onPressed: () {
  165. var page;
  166. if (Configuration.instance.getToken() == null) {
  167. page = EmailEntryPage();
  168. } else {
  169. // No key
  170. if (Configuration.instance.getKeyAttributes() != null) {
  171. // Yet to set or decrypt the key
  172. page = PassphraseReentryPage();
  173. } else {
  174. // Never had a key
  175. page = PassphraseEntryPage();
  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. }