Add Advanced privacy settings page and initial view model
OmarHatem committed
Oct 5, 2022 at 15:57 UTC
c37bfb2e83d2fe2ff48d911256b689dd8b53a03d
2 files changed
+227
lib/src/screens/new_wallet/advanced_privacy_settings_page.dart
new
+173
@@ -0,0 +1,173 @@
1
+import 'package:cake_wallet/entities/generate_name.dart';
2
+import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.dart';
3
+import 'package:cake_wallet/view_model/privacy_settings_view_model.dart';
4
+import 'package:flutter_mobx/flutter_mobx.dart';
5
+import 'package:flutter/material.dart';
6
+import 'package:flutter/cupertino.dart';
7
+import 'package:cake_wallet/generated/i18n.dart';
8
+import 'package:cake_wallet/core/wallet_name_validator.dart';
9
+import 'package:cake_wallet/src/screens/base_page.dart';
10
+import 'package:cake_wallet/src/widgets/primary_button.dart';
11
+import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
12
+
13
+class AdvancedPrivacySettingsPage extends BasePage {
14
+ AdvancedPrivacySettingsPage(this.privacySettingsViewModel);
15
+
16
+ final PrivacySettingsViewModel privacySettingsViewModel;
17
+
18
+ @override
19
+ String get title => S.current.privacy_settings;
20
+
21
+ @override
22
+ Widget body(BuildContext context) =>
23
+ AdvancedPrivacySettingsBody(privacySettingsViewModel);
24
+}
25
+
26
+class AdvancedPrivacySettingsBody extends StatefulWidget {
27
+ const AdvancedPrivacySettingsBody(this.privacySettingsViewModel, {Key key})
28
+ : super(key: key);
29
+
30
+ final PrivacySettingsViewModel privacySettingsViewModel;
31
+
32
+ @override
33
+ _AdvancedPrivacySettingsBodyState createState() =>
34
+ _AdvancedPrivacySettingsBodyState(privacySettingsViewModel);
35
+}
36
+
37
+class _AdvancedPrivacySettingsBodyState
38
+ extends State<AdvancedPrivacySettingsBody> {
39
+ _AdvancedPrivacySettingsBodyState(this.privacySettingsViewModel);
40
+
41
+ final PrivacySettingsViewModel privacySettingsViewModel;
42
+
43
+ final _formKey = GlobalKey<FormState>();
44
+
45
+ final TextEditingController _controller = TextEditingController();
46
+
47
+ @override
48
+ Widget build(BuildContext context) {
49
+ return Container(
50
+ padding: EdgeInsets.only(top: 24),
51
+ child: ScrollableWithBottomSection(
52
+ contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
53
+ content: Column(
54
+ crossAxisAlignment: CrossAxisAlignment.center,
55
+ children: [
56
+ ...privacySettingsViewModel.settings.map(
57
+ (item) => Observer(
58
+ builder: (_) => SettingsSwitcherCell(
59
+ title: item.title,
60
+ value: item.value(),
61
+ onValueChange: item.onValueChange,
62
+ ),
63
+ ),
64
+ ),
65
+ Observer(
66
+ builder: (_) {
67
+ if (privacySettingsViewModel.addCustomNode) {
68
+ return Padding(
69
+ padding: EdgeInsets.only(top: 24),
70
+ child: Form(
71
+ key: _formKey,
72
+ child: TextFormField(
73
+ onChanged: (value) {},
74
+ controller: _controller,
75
+ textAlign: TextAlign.center,
76
+ style: TextStyle(
77
+ fontSize: 20.0,
78
+ fontWeight: FontWeight.w600,
79
+ color:
80
+ Theme.of(context).primaryTextTheme.title.color),
81
+ decoration: InputDecoration(
82
+ hintStyle: TextStyle(
83
+ fontSize: 18.0,
84
+ fontWeight: FontWeight.w500,
85
+ color: Theme.of(context)
86
+ .accentTextTheme
87
+ .display3
88
+ .color),
89
+ hintText: S.of(context).wallet_name,
90
+ focusedBorder: UnderlineInputBorder(
91
+ borderSide: BorderSide(
92
+ color: Theme.of(context)
93
+ .accentTextTheme
94
+ .display3
95
+ .decorationColor,
96
+ width: 1.0),
97
+ ),
98
+ enabledBorder: UnderlineInputBorder(
99
+ borderSide: BorderSide(
100
+ color: Theme.of(context)
101
+ .accentTextTheme
102
+ .display3
103
+ .decorationColor,
104
+ width: 1.0),
105
+ ),
106
+ suffixIcon: IconButton(
107
+ onPressed: () async {
108
+ final rName = await generateName();
109
+ FocusManager.instance.primaryFocus?.unfocus();
110
+
111
+ setState(() {
112
+ _controller.text = rName;
113
+ _controller.selection =
114
+ TextSelection.fromPosition(
115
+ TextPosition(offset: _controller.text.length),
116
+ );
117
+ });
118
+ },
119
+ icon: Container(
120
+ padding: const EdgeInsets.all(8),
121
+ decoration: BoxDecoration(
122
+ borderRadius: BorderRadius.circular(6.0),
123
+ color: Theme.of(context).hintColor,
124
+ ),
125
+ width: 34,
126
+ height: 34,
127
+ child: Image.asset(
128
+ 'assets/images/refresh_icon.png',
129
+ color: Theme.of(context)
130
+ .primaryTextTheme
131
+ .display1
132
+ .decorationColor,
133
+ ),
134
+ ),
135
+ ),
136
+ ),
137
+ validator: WalletNameValidator(),
138
+ ),
139
+ ),
140
+ );
141
+ }
142
+ return const SizedBox();
143
+ },
144
+ ),
145
+ ],
146
+ ),
147
+ bottomSectionPadding: EdgeInsets.all(24),
148
+ bottomSection: Column(
149
+ children: [
150
+ LoadingPrimaryButton(
151
+ onPressed: () {},
152
+ text: S.of(context).continue_text,
153
+ color: Theme.of(context).accentTextTheme.body2.color,
154
+ textColor: Colors.white,
155
+ ),
156
+ const SizedBox(height: 25),
157
+ Padding(
158
+ padding: EdgeInsets.symmetric(
159
+ horizontal: MediaQuery.of(context).size.width * 0.15),
160
+ child: Text(
161
+ S.of(context).settings_can_be_changed_later,
162
+ textAlign: TextAlign.center,
163
+ style: TextStyle(
164
+ color: Theme.of(context).accentTextTheme.display3.color,
165
+ ),
166
+ ),
167
+ ),
168
+ ],
169
+ ),
170
+ ),
171
+ );
172
+ }
173
+}
lib/view_model/privacy_settings_view_model.dart
new
+54
@@ -0,0 +1,54 @@
1
+import 'package:cake_wallet/view_model/settings/switcher_list_item.dart';
2
+import 'package:cw_core/wallet_type.dart';
3
+import 'package:mobx/mobx.dart';
4
+import 'package:cake_wallet/generated/i18n.dart';
5
+
6
+part 'privacy_settings_view_model.g.dart';
7
+
8
+class PrivacySettingsViewModel = PrivacySettingsViewModelBase
9
+ with _$PrivacySettingsViewModel;
10
+
11
+abstract class PrivacySettingsViewModelBase with Store {
12
+ PrivacySettingsViewModelBase(this.type) {
13
+ _disableFiat = false;
14
+ _disableExchange = false;
15
+ _addCustomNode = false;
16
+
17
+ settings = [
18
+ SwitcherListItem(
19
+ title: "Disable Fiat API",
20
+ // title: S.current.disable_fiat,
21
+ value: () => _disableFiat,
22
+ onValueChange: (_, bool value) => _disableFiat = value,
23
+ ),
24
+ SwitcherListItem(
25
+ title: "Disable Exchange",
26
+ // title: S.current.disable_exchange,
27
+ value: () => _disableExchange,
28
+ onValueChange: (_, bool value) => _disableExchange = value,
29
+ ),
30
+ SwitcherListItem(
31
+ title: "Add New Custom Node",
32
+ // title: S.current.add_custom_node,
33
+ value: () => _addCustomNode,
34
+ onValueChange: (_, bool value) => _addCustomNode = value,
35
+ ),
36
+ ];
37
+ }
38
+
39
+ List<SwitcherListItem> settings;
40
+
41
+ @observable
42
+ bool _disableFiat;
43
+
44
+ @observable
45
+ bool _disableExchange;
46
+
47
+ @observable
48
+ bool _addCustomNode;
49
+
50
+ final WalletType type;
51
+
52
+ @computed
53
+ bool get addCustomNode => _addCustomNode;
54
+}