sign_in_header_widget.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. child: Container(
  146. width: double.infinity,
  147. height: 64,
  148. child: button(
  149. "sign in",
  150. fontSize: 18,
  151. onPressed: () {
  152. var page;
  153. if (Configuration.instance.getToken() == null) {
  154. page = EmailEntryPage();
  155. } else {
  156. // No key
  157. if (Configuration.instance.getKeyAttributes() != null) {
  158. // Yet to set or decrypt the key
  159. page = PassphraseReentryPage();
  160. } else {
  161. // Never had a key
  162. page = PassphraseEntryPage();
  163. }
  164. }
  165. Navigator.of(context).push(
  166. MaterialPageRoute(
  167. builder: (BuildContext context) {
  168. return page;
  169. },
  170. ),
  171. );
  172. },
  173. ),
  174. ),
  175. ),
  176. Padding(padding: EdgeInsets.all(10)),
  177. Divider(
  178. height: 2,
  179. ),
  180. ],
  181. ),
  182. ),
  183. );
  184. }
  185. }