Adding IconButton to generate names for wallet names for new_wallet and restore_wallet

This commit is contained in:
RafiaChy 2022-01-20 20:55:58 +06:00
parent 3bb338190e
commit 2b7d798253
3 changed files with 76 additions and 41 deletions

View file

@ -20,5 +20,6 @@ Future<String> generateName() async {
final chosenNoun = nouns[randomThing.nextInt(nouns.length)];
final returnString =
chosenAdjective.capitalized() + ' ' + chosenNoun.capitalized();
return returnString;
}

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/generate_name.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
@ -30,9 +31,11 @@ class NewWalletPage extends BasePage {
String get title => S.current.new_wallet;
@override
Widget body(BuildContext context) => WalletNameForm(_walletNewVM,
Widget body(BuildContext context) => WalletNameForm(
_walletNewVM,
currentTheme.type == ThemeType.dark
? walletNameImage : walletNameLightImage);
? walletNameImage
: walletNameLightImage);
}
class WalletNameForm extends StatefulWidget {
@ -55,12 +58,15 @@ class _WalletNameFormState extends State<WalletNameForm> {
ReactionDisposer _stateReaction;
final WalletNewVM _walletNewVM;
final TextEditingController _controller = TextEditingController();
@override
void initState() {
_stateReaction ??=
reaction((_) => _walletNewVM.state, (ExecutionState state) {
if (state is ExecutedSuccessfullyState) {
Navigator.of(context).pushNamed(Routes.preSeed, arguments: _walletNewVM.type);
Navigator.of(context)
.pushNamed(Routes.preSeed, arguments: _walletNewVM.type);
}
if (state is FailureState) {
@ -92,7 +98,8 @@ class _WalletNameFormState extends State<WalletNameForm> {
padding: EdgeInsets.only(left: 12, right: 12),
child: AspectRatio(
aspectRatio: aspectRatioImage,
child: FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
child:
FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
),
Padding(
padding: EdgeInsets.only(top: 24),
@ -100,20 +107,30 @@ class _WalletNameFormState extends State<WalletNameForm> {
key: _formKey,
child: TextFormField(
onChanged: (value) => _walletNewVM.name = value,
controller: _controller,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w600,
color:
Theme.of(context).primaryTextTheme.title.color),
color: Theme.of(context).primaryTextTheme.title.color),
decoration: InputDecoration(
suffixIcon: IconButton(
onPressed: () async {
final String rName = await generateName();
print(rName);
setState(() {
_controller.text = rName;
_walletNewVM.name = rName;
});
},
icon: Icon(Icons.refresh),
),
hintStyle: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.accentTextTheme
.display3
.color),
color:
Theme.of(context).accentTextTheme.display3.color),
hintText: S.of(context).wallet_name,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
@ -128,8 +145,12 @@ class _WalletNameFormState extends State<WalletNameForm> {
.accentTextTheme
.display3
.decorationColor,
width: 1.0))),
validator: WalletNameValidator())),
width: 1.0),
),
),
validator: WalletNameValidator(),
),
),
),
if (_walletNewVM.hasLanguageSelector) ...[
Padding(

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/generate_name.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/view_model/wallet_restore_view_model.dart';
import 'package:flutter/cupertino.dart';
@ -59,7 +60,19 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
BaseTextFormField(
controller: nameTextEditingController,
hintText: S.of(context).wallet_name,
validator: WalletNameValidator()),
validator: WalletNameValidator(),
suffixIcon: IconButton(
onPressed: () async {
final String rName = await generateName();
print(rName);
setState(() {
nameTextEditingController.text = rName;
});
},
icon: Icon(Icons.refresh),
),
),
Container(height: 20),
SeedWidget(
key: seedWidgetStateKey, language: language, type: widget.type),