password_reentry_page.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/widgets.dart';
  3. import 'package:logging/logging.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/ui/common/dynamicFAB.dart';
  8. import 'package:photos/ui/recovery_page.dart';
  9. import 'package:photos/utils/dialog_util.dart';
  10. class PasswordReentryPage extends StatefulWidget {
  11. PasswordReentryPage({Key key}) : super(key: key);
  12. @override
  13. _PasswordReentryPageState createState() => _PasswordReentryPageState();
  14. }
  15. class _PasswordReentryPageState extends State<PasswordReentryPage> {
  16. final _passwordController = TextEditingController();
  17. final FocusNode _passwordFocusNode = FocusNode();
  18. bool _passwordInFocus = false;
  19. bool _passwordVisible = false;
  20. @override
  21. void initState() {
  22. super.initState();
  23. _passwordFocusNode.addListener(() {
  24. setState(() {
  25. _passwordInFocus = _passwordFocusNode.hasFocus;
  26. });
  27. });
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom != 0;
  32. FloatingActionButtonLocation fabLocation() {
  33. if (isKeypadOpen) {
  34. return null;
  35. } else {
  36. return FloatingActionButtonLocation.centerFloat;
  37. }
  38. }
  39. return Scaffold(
  40. appBar: AppBar(
  41. elevation: 0,
  42. leading: IconButton(
  43. icon: Icon(Icons.arrow_back),
  44. color: Theme.of(context).iconTheme.color,
  45. onPressed: () {
  46. Navigator.of(context).pop();
  47. },
  48. ),
  49. ),
  50. body: _getBody(),
  51. floatingActionButton: DynamicFAB(
  52. isKeypadOpen: isKeypadOpen,
  53. isFormValid: _passwordController.text.isNotEmpty,
  54. buttonText: 'Log in',
  55. onPressedFunction: () async {
  56. final dialog = createProgressDialog(context, "please wait...");
  57. await dialog.show();
  58. try {
  59. await Configuration.instance.decryptAndSaveSecrets(
  60. _passwordController.text,
  61. Configuration.instance.getKeyAttributes());
  62. } catch (e) {
  63. Logger("PRP").warning(e);
  64. await dialog.hide();
  65. showErrorDialog(
  66. context, "incorrect password", "please try again");
  67. return;
  68. }
  69. await dialog.hide();
  70. Bus.instance.fire(SubscriptionPurchasedEvent());
  71. Navigator.of(context).popUntil((route) => route.isFirst);
  72. },
  73. ),
  74. floatingActionButtonLocation: fabLocation());
  75. }
  76. Widget _getBody() {
  77. return Column(
  78. children: [
  79. Expanded(
  80. child: ListView(
  81. children: [
  82. Padding(
  83. padding:
  84. const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
  85. child: Text('Welcome back!',
  86. style: Theme.of(context).textTheme.headline4),
  87. ),
  88. Padding(
  89. padding: const EdgeInsets.fromLTRB(20, 24, 20, 0),
  90. child: TextFormField(
  91. autofillHints: [AutofillHints.password],
  92. decoration: InputDecoration(
  93. hintText: "enter your password",
  94. filled: true,
  95. contentPadding: EdgeInsets.all(20),
  96. border: UnderlineInputBorder(
  97. borderSide: BorderSide.none,
  98. borderRadius: BorderRadius.circular(6)),
  99. suffixIcon: _passwordInFocus
  100. ? IconButton(
  101. icon: Icon(
  102. _passwordVisible
  103. ? Icons.visibility
  104. : Icons.visibility_off,
  105. color: Theme.of(context).iconTheme.color,
  106. size: 20,
  107. ),
  108. onPressed: () {
  109. setState(() {
  110. _passwordVisible = !_passwordVisible;
  111. });
  112. },
  113. )
  114. : null,
  115. ),
  116. style: TextStyle(
  117. fontSize: 14,
  118. ),
  119. controller: _passwordController,
  120. autofocus: true,
  121. autocorrect: false,
  122. obscureText: !_passwordVisible,
  123. keyboardType: TextInputType.visiblePassword,
  124. focusNode: _passwordFocusNode,
  125. onChanged: (_) {
  126. setState(() {});
  127. },
  128. ),
  129. ),
  130. Padding(
  131. padding: const EdgeInsets.symmetric(vertical: 18),
  132. child: Divider(
  133. thickness: 1,
  134. ),
  135. ),
  136. Padding(
  137. padding: const EdgeInsets.symmetric(horizontal: 20),
  138. child: Row(
  139. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  140. children: [
  141. GestureDetector(
  142. behavior: HitTestBehavior.opaque,
  143. onTap: () {
  144. Navigator.of(context).push(
  145. MaterialPageRoute(
  146. builder: (BuildContext context) {
  147. return RecoveryPage();
  148. },
  149. ),
  150. );
  151. },
  152. child: Container(
  153. child: Center(
  154. child: Text("forgot password",
  155. style: Theme.of(context)
  156. .textTheme
  157. .subtitle1
  158. .copyWith(
  159. fontSize: 14,
  160. decoration: TextDecoration.underline)),
  161. ),
  162. ),
  163. ),
  164. GestureDetector(
  165. behavior: HitTestBehavior.opaque,
  166. onTap: () async {
  167. final dialog =
  168. createProgressDialog(context, "please wait...");
  169. await dialog.show();
  170. await Configuration.instance.logout();
  171. await dialog.hide();
  172. Navigator.of(context)
  173. .popUntil((route) => route.isFirst);
  174. },
  175. child: Container(
  176. child: Center(
  177. child: Text("change email",
  178. style: Theme.of(context)
  179. .textTheme
  180. .subtitle1
  181. .copyWith(
  182. fontSize: 14,
  183. decoration: TextDecoration.underline)),
  184. ),
  185. ),
  186. ),
  187. ],
  188. ),
  189. )
  190. ],
  191. ),
  192. ),
  193. // Padding(padding: EdgeInsets.all(12)),
  194. // Container(
  195. // padding: const EdgeInsets.symmetric(horizontal: 60),
  196. // width: double.infinity,
  197. // height: 64,
  198. // child: OutlinedButton(
  199. // child: Text("log in"),
  200. // onPressed: _passwordController.text.isNotEmpty
  201. // ? () async {
  202. // final dialog =
  203. // createProgressDialog(context, "please wait...");
  204. // await dialog.show();
  205. // try {
  206. // await Configuration.instance.decryptAndSaveSecrets(
  207. // _passwordController.text,
  208. // Configuration.instance.getKeyAttributes());
  209. // } catch (e) {
  210. // Logger("PRP").warning(e);
  211. // await dialog.hide();
  212. // showErrorDialog(
  213. // context, "incorrect password", "please try again");
  214. // return;
  215. // }
  216. // await dialog.hide();
  217. // Bus.instance.fire(SubscriptionPurchasedEvent());
  218. // Navigator.of(context).popUntil((route) => route.isFirst);
  219. // }
  220. // : null,
  221. // ),
  222. // ),
  223. // Padding(padding: EdgeInsets.all(30)),
  224. ],
  225. );
  226. }
  227. }