From 4ef5f77888d9a53efb4589740a7727c35da1b246 Mon Sep 17 00:00:00 2001 From: poka Date: Tue, 6 Dec 2022 03:56:57 +0100 Subject: [PATCH] refacto: new WalletName Widget --- lib/providers/duniter_indexer.dart | 6 +-- lib/providers/wallet_options.dart | 55 ------------------- lib/widgets/template.dart | 18 +++++++ lib/widgets/wallet_name_controller.dart | 70 +++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 58 deletions(-) create mode 100644 lib/widgets/template.dart create mode 100644 lib/widgets/wallet_name_controller.dart diff --git a/lib/providers/duniter_indexer.dart b/lib/providers/duniter_indexer.dart index 5737f81..bce6f60 100644 --- a/lib/providers/duniter_indexer.dart +++ b/lib/providers/duniter_indexer.dart @@ -14,6 +14,7 @@ import 'package:gecko/providers/substrate_sdk.dart'; import 'package:gecko/providers/wallet_options.dart'; import 'package:gecko/providers/wallets_profiles.dart'; import 'package:gecko/screens/wallet_view.dart'; +import 'package:gecko/widgets/wallet_name_controller.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:provider/provider.dart'; import 'package:truncate/truncate.dart'; @@ -172,7 +173,7 @@ class DuniterIndexer with ChangeNotifier { if (canEdit) { return walletOptions.walletName(context, wallet, size, color); } else { - return walletOptions.walletNameController(context, wallet, size); + return WalletNameController(wallet: wallet, size: size); } } } @@ -224,8 +225,7 @@ class DuniterIndexer with ChangeNotifier { if (canEdit) { return walletOptions.walletName(context, wallet, size, color); } else { - return walletOptions.walletNameController( - context, wallet, size); + return WalletNameController(wallet: wallet, size: size); } } } diff --git a/lib/providers/wallet_options.dart b/lib/providers/wallet_options.dart index 6126fe2..86fe2ea 100644 --- a/lib/providers/wallet_options.dart +++ b/lib/providers/wallet_options.dart @@ -27,7 +27,6 @@ class WalletOptionsProvider with ChangeNotifier { TextEditingController newPin = TextEditingController(); bool isEditing = false; bool isBalanceBlur = false; - FocusNode walletNameFocus = FocusNode(); TextEditingController nameController = TextEditingController(); late bool isDefaultWallet; bool canValidateNameBool = false; @@ -392,60 +391,6 @@ class WalletOptionsProvider with ChangeNotifier { return addressGet; } - Widget walletNameController(BuildContext context, WalletData wallet, - [double size = 20]) { - nameController.text = wallet.name!; - - return SizedBox( - width: 260, - child: Stack(children: [ - TextField( - key: keyWalletName, - autofocus: false, - focusNode: walletNameFocus, - enabled: isEditing, - controller: nameController, - minLines: 1, - maxLines: 3, - textAlign: TextAlign.center, - decoration: const InputDecoration( - border: InputBorder.none, - focusedBorder: InputBorder.none, - enabledBorder: InputBorder.none, - disabledBorder: InputBorder.none, - contentPadding: EdgeInsets.all(15.0), - ), - style: TextStyle( - fontSize: isTall ? size : size * 0.9, - color: Colors.black, - fontWeight: FontWeight.w400, - ), - ), - Positioned( - right: 0, - child: InkWell( - key: keyRenameWallet, - onTap: () async { - // _isNewNameValid = - // walletProvider.editWalletName(wallet.id(), isCesium: false); - await editWalletName(context, wallet.id()); - await Future.delayed(const Duration(milliseconds: 30)); - walletNameFocus.requestFocus(); - }, - child: ClipRRect( - child: Image.asset( - isEditing - ? 'assets/walletOptions/android-checkmark.png' - : 'assets/walletOptions/edit.png', - width: 25, - height: 25), - ), - ), - ), - ]), - ); - } - Widget walletName(BuildContext context, WalletData wallet, [double size = 20, Color color = Colors.black]) { double newSize = wallet.name!.length <= 15 ? size : size - 2; diff --git a/lib/widgets/template.dart b/lib/widgets/template.dart new file mode 100644 index 0000000..566c410 --- /dev/null +++ b/lib/widgets/template.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; +import 'package:gecko/providers/substrate_sdk.dart'; +import 'package:provider/provider.dart'; + +class TemplateWidget extends StatelessWidget { + const TemplateWidget( + {Key? key, required this.address, this.color = Colors.black}) + : super(key: key); + final String address; + final Color color; + + @override + Widget build(BuildContext context) { + return Consumer(builder: (context, sub, _) { + return const Text('Hello Widget'); + }); + } +} diff --git a/lib/widgets/wallet_name_controller.dart b/lib/widgets/wallet_name_controller.dart new file mode 100644 index 0000000..be6253d --- /dev/null +++ b/lib/widgets/wallet_name_controller.dart @@ -0,0 +1,70 @@ +import 'package:flutter/material.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/wallet_data.dart'; +import 'package:gecko/models/widgets_keys.dart'; +import 'package:gecko/providers/wallet_options.dart'; +import 'package:provider/provider.dart'; + +class WalletNameController extends StatelessWidget { + const WalletNameController({Key? key, required this.wallet, this.size = 20}) + : super(key: key); + final WalletData wallet; + final double size; + + @override + Widget build(BuildContext context) { + final walletOptions = + Provider.of(context, listen: false); + walletOptions.nameController.text = wallet.name!; + final walletNameFocus = FocusNode(); + + return SizedBox( + width: 260, + child: Stack(children: [ + TextField( + key: keyWalletName, + autofocus: false, + focusNode: walletNameFocus, + enabled: walletOptions.isEditing, + controller: walletOptions.nameController, + minLines: 1, + maxLines: 3, + textAlign: TextAlign.center, + decoration: const InputDecoration( + border: InputBorder.none, + focusedBorder: InputBorder.none, + enabledBorder: InputBorder.none, + disabledBorder: InputBorder.none, + contentPadding: EdgeInsets.all(15.0), + ), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: Colors.black, + fontWeight: FontWeight.w400, + ), + ), + Positioned( + right: 0, + child: InkWell( + key: keyRenameWallet, + onTap: () async { + // _isNewNameValid = + // walletProvider.editWalletName(wallet.id(), isCesium: false); + await walletOptions.editWalletName(context, wallet.id()); + await Future.delayed(const Duration(milliseconds: 30)); + walletNameFocus.requestFocus(); + }, + child: ClipRRect( + child: Image.asset( + walletOptions.isEditing + ? 'assets/walletOptions/android-checkmark.png' + : 'assets/walletOptions/edit.png', + width: 25, + height: 25), + ), + ), + ), + ]), + ); + } +}