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 chosenNoun = nouns[randomThing.nextInt(nouns.length)];
final returnString = final returnString =
chosenAdjective.capitalized() + ' ' + chosenNoun.capitalized(); chosenAdjective.capitalized() + ' ' + chosenNoun.capitalized();
return returnString; 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/routes.dart';
import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/utils/show_pop_up.dart';
@ -24,15 +25,17 @@ class NewWalletPage extends BasePage {
final walletNameImage = Image.asset('assets/images/wallet_name.png'); final walletNameImage = Image.asset('assets/images/wallet_name.png');
final walletNameLightImage = final walletNameLightImage =
Image.asset('assets/images/wallet_name_light.png'); Image.asset('assets/images/wallet_name_light.png');
@override @override
String get title => S.current.new_wallet; String get title => S.current.new_wallet;
@override @override
Widget body(BuildContext context) => WalletNameForm(_walletNewVM, Widget body(BuildContext context) => WalletNameForm(
_walletNewVM,
currentTheme.type == ThemeType.dark currentTheme.type == ThemeType.dark
? walletNameImage : walletNameLightImage); ? walletNameImage
: walletNameLightImage);
} }
class WalletNameForm extends StatefulWidget { class WalletNameForm extends StatefulWidget {
@ -55,12 +58,15 @@ class _WalletNameFormState extends State<WalletNameForm> {
ReactionDisposer _stateReaction; ReactionDisposer _stateReaction;
final WalletNewVM _walletNewVM; final WalletNewVM _walletNewVM;
final TextEditingController _controller = TextEditingController();
@override @override
void initState() { void initState() {
_stateReaction ??= _stateReaction ??=
reaction((_) => _walletNewVM.state, (ExecutionState state) { reaction((_) => _walletNewVM.state, (ExecutionState state) {
if (state is ExecutedSuccessfullyState) { 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) { if (state is FailureState) {
@ -92,44 +98,59 @@ class _WalletNameFormState extends State<WalletNameForm> {
padding: EdgeInsets.only(left: 12, right: 12), padding: EdgeInsets.only(left: 12, right: 12),
child: AspectRatio( child: AspectRatio(
aspectRatio: aspectRatioImage, aspectRatio: aspectRatioImage,
child: FittedBox(child: widget.walletImage, fit: BoxFit.fill)), child:
FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
), ),
Padding( Padding(
padding: EdgeInsets.only(top: 24), padding: EdgeInsets.only(top: 24),
child: Form( child: Form(
key: _formKey, key: _formKey,
child: TextFormField( child: TextFormField(
onChanged: (value) => _walletNewVM.name = value, onChanged: (value) => _walletNewVM.name = value,
textAlign: TextAlign.center, controller: _controller,
style: TextStyle( textAlign: TextAlign.center,
fontSize: 20.0, style: TextStyle(
fontWeight: FontWeight.w600, fontSize: 20.0,
color: fontWeight: FontWeight.w600,
Theme.of(context).primaryTextTheme.title.color), color: Theme.of(context).primaryTextTheme.title.color),
decoration: InputDecoration( decoration: InputDecoration(
hintStyle: TextStyle( suffixIcon: IconButton(
fontSize: 18.0, onPressed: () async {
fontWeight: FontWeight.w500, final String rName = await generateName();
color: Theme.of(context)
.accentTextTheme print(rName);
.display3 setState(() {
.color), _controller.text = rName;
hintText: S.of(context).wallet_name, _walletNewVM.name = rName;
focusedBorder: UnderlineInputBorder( });
borderSide: BorderSide( },
color: Theme.of(context) icon: Icon(Icons.refresh),
.accentTextTheme ),
.display3 hintStyle: TextStyle(
.decorationColor, fontSize: 18.0,
width: 1.0)), fontWeight: FontWeight.w500,
enabledBorder: UnderlineInputBorder( color:
borderSide: BorderSide( Theme.of(context).accentTextTheme.display3.color),
color: Theme.of(context) hintText: S.of(context).wallet_name,
.accentTextTheme focusedBorder: UnderlineInputBorder(
.display3 borderSide: BorderSide(
.decorationColor, color: Theme.of(context)
width: 1.0))), .accentTextTheme
validator: WalletNameValidator())), .display3
.decorationColor,
width: 1.0)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context)
.accentTextTheme
.display3
.decorationColor,
width: 1.0),
),
),
validator: WalletNameValidator(),
),
),
), ),
if (_walletNewVM.hasLanguageSelector) ...[ if (_walletNewVM.hasLanguageSelector) ...[
Padding( Padding(

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/generate_name.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/view_model/wallet_restore_view_model.dart'; import 'package:cake_wallet/view_model/wallet_restore_view_model.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -57,9 +58,21 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
padding: EdgeInsets.only(left: 24, right: 24), padding: EdgeInsets.only(left: 24, right: 24),
child: Column(children: [ child: Column(children: [
BaseTextFormField( BaseTextFormField(
controller: nameTextEditingController, controller: nameTextEditingController,
hintText: S.of(context).wallet_name, 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), Container(height: 20),
SeedWidget( SeedWidget(
key: seedWidgetStateKey, language: language, type: widget.type), key: seedWidgetStateKey, language: language, type: widget.type),