dev
dart 106 lines 3.93 KB
Raw
1 import 'package:cake_wallet/new-ui/widgets/receive_page/receive_top_bar.dart';
2 import 'package:flutter/material.dart';
3 import 'package:flutter_mobx/flutter_mobx.dart';
4 import 'package:cake_wallet/generated/i18n.dart';
5 import 'package:cake_wallet/utils/show_pop_up.dart';
6 import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
7 import 'package:cake_wallet/src/widgets/primary_button.dart';
8 import 'package:cake_wallet/view_model/edit_backup_password_view_model.dart';
9
10 class EditBackupPasswordPage extends StatefulWidget {
11 EditBackupPasswordPage(this.editBackupPasswordViewModel);
12
13 final EditBackupPasswordViewModel editBackupPasswordViewModel;
14
15 @override
16 State<EditBackupPasswordPage> createState() => _EditBackupPasswordPageState();
17 }
18
19 class _EditBackupPasswordPageState extends State<EditBackupPasswordPage> {
20 final textEditingController = TextEditingController();
21
22 @override
23 void initState() {
24 super.initState();
25 textEditingController.text = widget.editBackupPasswordViewModel.backupPassword;
26 textEditingController.addListener(() {
27 if (textEditingController.text != widget.editBackupPasswordViewModel.backupPassword) {
28 widget.editBackupPasswordViewModel.backupPassword = textEditingController.text;
29 }
30 });
31 }
32
33 @override
34 Widget build(BuildContext context) {
35 return Column(children: [
36 ModalTopBar(
37 title: S.of(context).edit_backup_password,
38 leadingIcon: Icon(Icons.arrow_back_ios_new),
39 leadingSemanticLabel: S.of(context).seed_alert_back,
40 onLeadingPressed: Navigator.of(context).pop,
41 ),
42 Expanded(
43 child: SafeArea(
44 child: Padding(
45 padding: EdgeInsets.only(
46 left: 24, right: 24, bottom: MediaQuery.of(context).viewInsets.bottom),
47 child: Stack(
48 fit: StackFit.expand,
49 children: [
50 Center(
51 child: Observer(
52 builder: (_) => TextFormField(
53 enableSuggestions: false,
54 autocorrect: false,
55 keyboardType: TextInputType.visiblePassword,
56 controller: textEditingController,
57 style: Theme.of(context).textTheme.titleLarge?.copyWith(
58 color: Theme.of(context).colorScheme.onSurface,
59 ),
60 ),
61 ),
62 ),
63 Positioned(
64 child: Observer(
65 builder: (_) => PrimaryButton(
66 onPressed: () => onSave(context),
67 text: S.of(context).save,
68 color: Theme.of(context).colorScheme.primary,
69 textColor: Theme.of(context).colorScheme.onPrimary,
70 isDisabled: !widget.editBackupPasswordViewModel.canSave,
71 ),
72 ),
73 bottom: 24,
74 left: 0,
75 right: 0,
76 )
77 ],
78 ),
79 ),
80 ),
81 ),
82 ]);
83 }
84
85 void onSave(BuildContext context) {
86 FocusScope.of(context).unfocus();
87 showPopUp<void>(
88 context: context,
89 builder: (dialogContext) {
90 return AlertWithTwoActions(
91 alertTitle: S.of(context).save_backup_password_alert,
92 alertContent: S.of(context).change_backup_password_alert,
93 rightButtonText: S.of(context).ok,
94 leftButtonText: S.of(context).cancel,
95 actionRightButton: () async {
96 widget.editBackupPasswordViewModel.backupPassword = textEditingController.text;
97 await widget.editBackupPasswordViewModel.save();
98 Navigator.of(dialogContext).pop();
99 if (context.mounted) {
100 Navigator.of(context).pop();
101 }
102 },
103 actionLeftButton: () => Navigator.of(dialogContext).pop());
104 });
105 }
106 }