password_reentry_page.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_elements.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. 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. return Scaffold(
  32. appBar: AppBar(
  33. title: Text(
  34. "password",
  35. ),
  36. ),
  37. body: _getBody(),
  38. );
  39. }
  40. Widget _getBody() {
  41. return Column(
  42. crossAxisAlignment: CrossAxisAlignment.stretch,
  43. mainAxisAlignment: MainAxisAlignment.center,
  44. mainAxisSize: MainAxisSize.max,
  45. children: [
  46. Padding(
  47. padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
  48. child: TextFormField(
  49. decoration: InputDecoration(
  50. hintText: "enter your password",
  51. contentPadding: EdgeInsets.all(20),
  52. suffixIcon: _passwordInFocus
  53. ? IconButton(
  54. icon: Icon(
  55. _passwordVisible
  56. ? Icons.visibility
  57. : Icons.visibility_off,
  58. color: Colors.white.withOpacity(0.5),
  59. size: 20,
  60. ),
  61. onPressed: () {
  62. setState(() {
  63. _passwordVisible = !_passwordVisible;
  64. });
  65. },
  66. )
  67. : null,
  68. ),
  69. style: TextStyle(
  70. fontSize: 14,
  71. ),
  72. controller: _passwordController,
  73. autofocus: false,
  74. autocorrect: false,
  75. obscureText: !_passwordVisible,
  76. keyboardType: TextInputType.visiblePassword,
  77. focusNode: _passwordFocusNode,
  78. onChanged: (_) {
  79. setState(() {});
  80. },
  81. ),
  82. ),
  83. Padding(padding: EdgeInsets.all(12)),
  84. Container(
  85. padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
  86. width: double.infinity,
  87. height: 64,
  88. child: button(
  89. "sign in",
  90. fontSize: 18,
  91. onPressed: _passwordController.text.isNotEmpty
  92. ? () async {
  93. final dialog =
  94. createProgressDialog(context, "please wait...");
  95. await dialog.show();
  96. try {
  97. await Configuration.instance.decryptAndSaveKey(
  98. _passwordController.text,
  99. Configuration.instance.getKeyAttributes());
  100. } catch (e) {
  101. Logger("PRP").warning(e);
  102. await dialog.hide();
  103. showErrorDialog(
  104. context, "incorrect password", "please try again");
  105. return;
  106. }
  107. await dialog.hide();
  108. Bus.instance.fire(SubscriptionPurchasedEvent());
  109. Navigator.of(context).popUntil((route) => route.isFirst);
  110. }
  111. : null,
  112. ),
  113. ),
  114. Padding(padding: EdgeInsets.all(30)),
  115. GestureDetector(
  116. behavior: HitTestBehavior.opaque,
  117. onTap: () {
  118. Navigator.of(context).push(
  119. MaterialPageRoute(
  120. builder: (BuildContext context) {
  121. return RecoveryPage();
  122. },
  123. ),
  124. );
  125. },
  126. child: Container(
  127. padding: EdgeInsets.all(10),
  128. child: Center(
  129. child: Text(
  130. "forgot password?",
  131. style: TextStyle(
  132. decoration: TextDecoration.underline,
  133. fontSize: 12,
  134. ),
  135. ),
  136. ),
  137. ),
  138. ),
  139. ],
  140. );
  141. }
  142. }