password_reentry_page.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/services/billing_service.dart';
  6. import 'package:photos/ui/common_elements.dart';
  7. import 'package:photos/ui/subscription_page.dart';
  8. import 'package:photos/utils/dialog_util.dart';
  9. class PasswordReentryPage extends StatefulWidget {
  10. PasswordReentryPage({Key key}) : super(key: key);
  11. @override
  12. _PasswordReentryPageState createState() => _PasswordReentryPageState();
  13. }
  14. class _PasswordReentryPageState extends State<PasswordReentryPage> {
  15. final _passwordController = TextEditingController();
  16. @override
  17. Widget build(BuildContext context) {
  18. return Scaffold(
  19. appBar: AppBar(
  20. leading: Icon(Icons.lock),
  21. title: Text(
  22. "encryption password",
  23. ),
  24. ),
  25. body: _getBody(),
  26. );
  27. }
  28. Widget _getBody() {
  29. return SingleChildScrollView(
  30. child: Container(
  31. padding: EdgeInsets.fromLTRB(16, 40, 16, 16),
  32. child: Column(
  33. children: [
  34. Image.asset(
  35. "assets/vault.png",
  36. width: 196,
  37. height: 196,
  38. ),
  39. Padding(padding: EdgeInsets.all(20)),
  40. Padding(
  41. padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
  42. child: TextFormField(
  43. decoration: InputDecoration(
  44. hintText: "enter your password",
  45. contentPadding: EdgeInsets.all(20),
  46. ),
  47. style: TextStyle(
  48. fontSize: 14,
  49. ),
  50. controller: _passwordController,
  51. autofocus: false,
  52. autocorrect: false,
  53. obscureText: true,
  54. keyboardType: TextInputType.visiblePassword,
  55. onChanged: (_) {
  56. setState(() {});
  57. },
  58. ),
  59. ),
  60. Padding(padding: EdgeInsets.all(12)),
  61. Container(
  62. padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
  63. width: double.infinity,
  64. height: 64,
  65. child: button(
  66. "sign in",
  67. fontSize: 18,
  68. onPressed: _passwordController.text.isNotEmpty
  69. ? () async {
  70. final dialog =
  71. createProgressDialog(context, "please wait...");
  72. await dialog.show();
  73. try {
  74. await Configuration.instance.decryptAndSaveKey(
  75. _passwordController.text,
  76. Configuration.instance.getKeyAttributes());
  77. } catch (e) {
  78. Logger("PRP").warning(e);
  79. await dialog.hide();
  80. showErrorDialog(context, "incorrect password",
  81. "please try again");
  82. return;
  83. }
  84. await dialog.hide();
  85. if (!BillingService.instance
  86. .hasActiveSubscription()) {
  87. Navigator.of(context).push(
  88. MaterialPageRoute(
  89. builder: (BuildContext context) {
  90. return SubscriptionPage();
  91. },
  92. ),
  93. );
  94. } else {
  95. Navigator.of(context)
  96. .popUntil((route) => route.isFirst);
  97. }
  98. }
  99. : null,
  100. )),
  101. ],
  102. ),
  103. ),
  104. );
  105. }
  106. }