feat: Edit wallet name in popup
This commit is contained in:
parent
9ec7a6594d
commit
63c71fed01
|
@ -23,6 +23,7 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
FocusNode walletNameFocus = FocusNode();
|
FocusNode walletNameFocus = FocusNode();
|
||||||
TextEditingController nameController = TextEditingController();
|
TextEditingController nameController = TextEditingController();
|
||||||
late bool isDefaultWallet;
|
late bool isDefaultWallet;
|
||||||
|
bool canValidateNameBool = false;
|
||||||
|
|
||||||
Future<NewWallet>? get badWallet => null;
|
Future<NewWallet>? get badWallet => null;
|
||||||
|
|
||||||
|
@ -41,25 +42,6 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
_newWalletName.text = '';
|
_newWalletName.text = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool editWalletName(List<int?> _wID, {bool? isCesium}) {
|
|
||||||
bool nameState;
|
|
||||||
if (isEditing) {
|
|
||||||
if (!nameController.text.contains(':') &&
|
|
||||||
nameController.text.length <= 39) {
|
|
||||||
_renameWallet(_wID, nameController.text, isCesium: isCesium!);
|
|
||||||
nameState = true;
|
|
||||||
} else {
|
|
||||||
nameState = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
nameState = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
isEditing ? isEditing = false : isEditing = true;
|
|
||||||
notifyListeners();
|
|
||||||
return nameState;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<int> deleteWallet(context, WalletData wallet) async {
|
Future<int> deleteWallet(context, WalletData wallet) async {
|
||||||
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||||
final bool? _answer = await (confirmPopup(context,
|
final bool? _answer = await (confirmPopup(context,
|
||||||
|
@ -290,6 +272,111 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String?> editWalletName(BuildContext context, List<int?> _wID) async {
|
||||||
|
TextEditingController walletName = TextEditingController();
|
||||||
|
canValidateNameBool = false;
|
||||||
|
|
||||||
|
return showDialog<String>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: true,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text(
|
||||||
|
'Choisissez un nouveau nom\n pour votre portefeuille :',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
content: SizedBox(
|
||||||
|
height: 100,
|
||||||
|
child: Column(children: [
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
TextField(
|
||||||
|
onChanged: (_) => canValidateName(context, walletName),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
autofocus: true,
|
||||||
|
controller: walletName,
|
||||||
|
style: const TextStyle(fontSize: 19),
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Consumer<WalletOptionsProvider>(
|
||||||
|
builder: (context, _wOptions, _) {
|
||||||
|
return TextButton(
|
||||||
|
key: const Key('infoPopup'),
|
||||||
|
child: Text(
|
||||||
|
"Valider",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 21,
|
||||||
|
color: canValidateNameBool
|
||||||
|
? const Color(0xffD80000)
|
||||||
|
: Colors.grey,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
if (canValidateNameBool) {
|
||||||
|
nameController.text = walletName.text;
|
||||||
|
_renameWallet(_wID, walletName.text, isCesium: false);
|
||||||
|
// notifyListeners();
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
})
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
key: const Key('cancel'),
|
||||||
|
child: Text(
|
||||||
|
"Annuler",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
color: Colors.grey[800],
|
||||||
|
fontWeight: FontWeight.w300),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool canValidateName(BuildContext context, TextEditingController walletName) {
|
||||||
|
MyWalletsProvider _myWalletProvider =
|
||||||
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||||
|
|
||||||
|
bool isNameValid = walletName.text.length >= 2 &&
|
||||||
|
!walletName.text.contains(':') &&
|
||||||
|
walletName.text.length <= 39;
|
||||||
|
|
||||||
|
if (isNameValid) {
|
||||||
|
for (var wallet in _myWalletProvider.listWallets) {
|
||||||
|
if (walletName.text == wallet.name!) {
|
||||||
|
canValidateNameBool = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
canValidateNameBool = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
canValidateNameBool = false;
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
return canValidateNameBool;
|
||||||
|
}
|
||||||
|
|
||||||
void reloadBuild() {
|
void reloadBuild() {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,8 @@ class WalletOptions extends StatelessWidget {
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
walletName(walletProvider, _walletOptions),
|
walletName(
|
||||||
|
context, walletProvider, _walletOptions),
|
||||||
SizedBox(height: isTall ? 5 : 0),
|
SizedBox(height: isTall ? 5 : 0),
|
||||||
// SizedBox(height: isTall ? 5 : 0),
|
// SizedBox(height: isTall ? 5 : 0),
|
||||||
balance(
|
balance(
|
||||||
|
@ -246,7 +247,7 @@ class WalletOptions extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget walletName(WalletOptionsProvider walletProvider,
|
Widget walletName(BuildContext context, WalletOptionsProvider walletProvider,
|
||||||
WalletOptionsProvider _walletOptions) {
|
WalletOptionsProvider _walletOptions) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_walletOptions.nameController.text = wallet.name!;
|
_walletOptions.nameController.text = wallet.name!;
|
||||||
|
@ -284,7 +285,8 @@ class WalletOptions extends StatelessWidget {
|
||||||
key: const Key('renameWallet'),
|
key: const Key('renameWallet'),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
// _isNewNameValid =
|
// _isNewNameValid =
|
||||||
walletProvider.editWalletName(wallet.id(), isCesium: false);
|
// walletProvider.editWalletName(wallet.id(), isCesium: false);
|
||||||
|
await walletProvider.editWalletName(context, wallet.id());
|
||||||
await Future.delayed(const Duration(milliseconds: 30));
|
await Future.delayed(const Duration(milliseconds: 30));
|
||||||
walletProvider.walletNameFocus.requestFocus();
|
walletProvider.walletNameFocus.requestFocus();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue