diff --git a/lib/entities/generate_name.dart b/lib/entities/generate_name.dart index 4aa570769..140a60b31 100644 --- a/lib/entities/generate_name.dart +++ b/lib/entities/generate_name.dart @@ -20,5 +20,6 @@ Future generateName() async { final chosenNoun = nouns[randomThing.nextInt(nouns.length)]; final returnString = chosenAdjective.capitalized() + ' ' + chosenNoun.capitalized(); + return returnString; } diff --git a/lib/src/screens/new_wallet/new_wallet_page.dart b/lib/src/screens/new_wallet/new_wallet_page.dart index 79998e944..ad4f5560b 100644 --- a/lib/src/screens/new_wallet/new_wallet_page.dart +++ b/lib/src/screens/new_wallet/new_wallet_page.dart @@ -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'; @@ -24,15 +25,17 @@ class NewWalletPage extends BasePage { final walletNameImage = Image.asset('assets/images/wallet_name.png'); final walletNameLightImage = - Image.asset('assets/images/wallet_name_light.png'); + Image.asset('assets/images/wallet_name_light.png'); @override 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 { 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,44 +98,59 @@ class _WalletNameFormState extends State { 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), child: Form( - key: _formKey, - child: TextFormField( - onChanged: (value) => _walletNewVM.name = value, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 20.0, - fontWeight: FontWeight.w600, - color: - Theme.of(context).primaryTextTheme.title.color), - decoration: InputDecoration( - hintStyle: TextStyle( - fontSize: 18.0, - fontWeight: FontWeight.w500, - color: Theme.of(context) - .accentTextTheme - .display3 - .color), - hintText: S.of(context).wallet_name, - focusedBorder: UnderlineInputBorder( - borderSide: BorderSide( - color: Theme.of(context) - .accentTextTheme - .display3 - .decorationColor, - width: 1.0)), - enabledBorder: UnderlineInputBorder( - borderSide: BorderSide( - color: Theme.of(context) - .accentTextTheme - .display3 - .decorationColor, - width: 1.0))), - validator: WalletNameValidator())), + 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), + 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), + hintText: S.of(context).wallet_name, + focusedBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: Theme.of(context) + .accentTextTheme + .display3 + .decorationColor, + width: 1.0)), + enabledBorder: UnderlineInputBorder( + borderSide: BorderSide( + color: Theme.of(context) + .accentTextTheme + .display3 + .decorationColor, + width: 1.0), + ), + ), + validator: WalletNameValidator(), + ), + ), ), if (_walletNewVM.hasLanguageSelector) ...[ Padding( diff --git a/lib/src/screens/restore/wallet_restore_from_seed_form.dart b/lib/src/screens/restore/wallet_restore_from_seed_form.dart index 0b327f387..97507f49e 100644 --- a/lib/src/screens/restore/wallet_restore_from_seed_form.dart +++ b/lib/src/screens/restore/wallet_restore_from_seed_form.dart @@ -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'; @@ -57,9 +58,21 @@ class WalletRestoreFromSeedFormState extends State { padding: EdgeInsets.only(left: 24, right: 24), child: Column(children: [ BaseTextFormField( - controller: nameTextEditingController, - hintText: S.of(context).wallet_name, - validator: WalletNameValidator()), + controller: nameTextEditingController, + hintText: S.of(context).wallet_name, + 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),