Adding IconButton to generate names for wallet names for new_wallet and restore_wallet
RafiaChy committed
Jan 20, 2022 at 20:55 UTC
2b7d7982530c56009588e5a4990e0e6e420bd5a3
3 files changed
+76
-41
lib/entities/generate_name.dart
+1
@@ -20,5 +20,6 @@ Future<String> generateName() async {
20
final chosenNoun = nouns[randomThing.nextInt(nouns.length)];
21
final returnString =
22
chosenAdjective.capitalized() + ' ' + chosenNoun.capitalized();
23
+
24
return returnString;
25
}
lib/src/screens/new_wallet/new_wallet_page.dart
+59
-38
@@ -1,3 +1,4 @@
1
+import 'package:cake_wallet/entities/generate_name.dart';
2
import 'package:cake_wallet/routes.dart';
3
import 'package:cake_wallet/themes/theme_base.dart';
4
import 'package:cake_wallet/utils/show_pop_up.dart';
@@ -24,15 +25,17 @@ class NewWalletPage extends BasePage {
25
final walletNameImage = Image.asset('assets/images/wallet_name.png');
26
27
final walletNameLightImage =
27
- Image.asset('assets/images/wallet_name_light.png');
28
+ Image.asset('assets/images/wallet_name_light.png');
29
30
@override
31
String get title => S.current.new_wallet;
32
33
@override
33
- Widget body(BuildContext context) => WalletNameForm(_walletNewVM,
34
+ Widget body(BuildContext context) => WalletNameForm(
35
+ _walletNewVM,
36
currentTheme.type == ThemeType.dark
35
- ? walletNameImage : walletNameLightImage);
37
+ ? walletNameImage
38
+ : walletNameLightImage);
39
}
40
41
class WalletNameForm extends StatefulWidget {
@@ -55,12 +58,15 @@ class _WalletNameFormState extends State<WalletNameForm> {
58
ReactionDisposer _stateReaction;
59
final WalletNewVM _walletNewVM;
60
61
+ final TextEditingController _controller = TextEditingController();
62
+
63
@override
64
void initState() {
65
_stateReaction ??=
66
reaction((_) => _walletNewVM.state, (ExecutionState state) {
67
if (state is ExecutedSuccessfullyState) {
63
- Navigator.of(context).pushNamed(Routes.preSeed, arguments: _walletNewVM.type);
68
+ Navigator.of(context)
69
+ .pushNamed(Routes.preSeed, arguments: _walletNewVM.type);
70
}
71
72
if (state is FailureState) {
@@ -92,44 +98,59 @@ class _WalletNameFormState extends State<WalletNameForm> {
98
padding: EdgeInsets.only(left: 12, right: 12),
99
child: AspectRatio(
100
aspectRatio: aspectRatioImage,
95
- child: FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
101
+ child:
102
+ FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
103
),
104
Padding(
105
padding: EdgeInsets.only(top: 24),
106
child: Form(
100
- key: _formKey,
101
- child: TextFormField(
102
- onChanged: (value) => _walletNewVM.name = value,
103
- textAlign: TextAlign.center,
104
- style: TextStyle(
105
- fontSize: 20.0,
106
- fontWeight: FontWeight.w600,
107
- color:
108
- Theme.of(context).primaryTextTheme.title.color),
109
- decoration: InputDecoration(
110
- hintStyle: TextStyle(
111
- fontSize: 18.0,
112
- fontWeight: FontWeight.w500,
113
- color: Theme.of(context)
114
- .accentTextTheme
115
- .display3
116
- .color),
117
- hintText: S.of(context).wallet_name,
118
- focusedBorder: UnderlineInputBorder(
119
- borderSide: BorderSide(
120
- color: Theme.of(context)
121
- .accentTextTheme
122
- .display3
123
- .decorationColor,
124
- width: 1.0)),
125
- enabledBorder: UnderlineInputBorder(
126
- borderSide: BorderSide(
127
- color: Theme.of(context)
128
- .accentTextTheme
129
- .display3
130
- .decorationColor,
131
- width: 1.0))),
132
- validator: WalletNameValidator())),
107
+ key: _formKey,
108
+ child: TextFormField(
109
+ onChanged: (value) => _walletNewVM.name = value,
110
+ controller: _controller,
111
+ textAlign: TextAlign.center,
112
+ style: TextStyle(
113
+ fontSize: 20.0,
114
+ fontWeight: FontWeight.w600,
115
+ color: Theme.of(context).primaryTextTheme.title.color),
116
+ decoration: InputDecoration(
117
+ suffixIcon: IconButton(
118
+ onPressed: () async {
119
+ final String rName = await generateName();
120
+
121
+ print(rName);
122
+ setState(() {
123
+ _controller.text = rName;
124
+ _walletNewVM.name = rName;
125
+ });
126
+ },
127
+ icon: Icon(Icons.refresh),
128
+ ),
129
+ hintStyle: TextStyle(
130
+ fontSize: 18.0,
131
+ fontWeight: FontWeight.w500,
132
+ color:
133
+ Theme.of(context).accentTextTheme.display3.color),
134
+ hintText: S.of(context).wallet_name,
135
+ focusedBorder: UnderlineInputBorder(
136
+ borderSide: BorderSide(
137
+ color: Theme.of(context)
138
+ .accentTextTheme
139
+ .display3
140
+ .decorationColor,
141
+ width: 1.0)),
142
+ enabledBorder: UnderlineInputBorder(
143
+ borderSide: BorderSide(
144
+ color: Theme.of(context)
145
+ .accentTextTheme
146
+ .display3
147
+ .decorationColor,
148
+ width: 1.0),
149
+ ),
150
+ ),
151
+ validator: WalletNameValidator(),
152
+ ),
153
+ ),
154
),
155
if (_walletNewVM.hasLanguageSelector) ...[
156
Padding(
lib/src/screens/restore/wallet_restore_from_seed_form.dart
+16
-3
@@ -1,3 +1,4 @@
1
+import 'package:cake_wallet/entities/generate_name.dart';
2
import 'package:cw_core/wallet_type.dart';
3
import 'package:cake_wallet/view_model/wallet_restore_view_model.dart';
4
import 'package:flutter/cupertino.dart';
@@ -57,9 +58,21 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
58
padding: EdgeInsets.only(left: 24, right: 24),
59
child: Column(children: [
60
BaseTextFormField(
60
- controller: nameTextEditingController,
61
- hintText: S.of(context).wallet_name,
62
- validator: WalletNameValidator()),
61
+ controller: nameTextEditingController,
62
+ hintText: S.of(context).wallet_name,
63
+ validator: WalletNameValidator(),
64
+ suffixIcon: IconButton(
65
+ onPressed: () async {
66
+ final String rName = await generateName();
67
+
68
+ print(rName);
69
+ setState(() {
70
+ nameTextEditingController.text = rName;
71
+ });
72
+ },
73
+ icon: Icon(Icons.refresh),
74
+ ),
75
+ ),
76
Container(height: 20),
77
SeedWidget(
78
key: seedWidgetStateKey, language: language, type: widget.type),