-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add editWalletDetails widget add delete method
- Loading branch information
Showing
3 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | ||
import 'package:my_wit_wallet/util/get_localization.dart'; | ||
|
||
import 'package:my_wit_wallet/shared/api_database.dart'; | ||
import 'package:my_wit_wallet/shared/locator.dart'; | ||
import 'package:my_wit_wallet/util/storage/database/wallet.dart'; | ||
|
||
import 'package:my_wit_wallet/screens/dashboard/bloc/dashboard_bloc.dart'; | ||
|
||
class EditWalletDetails extends StatefulWidget { | ||
@override | ||
State<StatefulWidget> createState() => EditWalletDetailsState(); | ||
} | ||
|
||
class EditWalletDetailsState extends State<EditWalletDetails> { | ||
late TextEditingController _nameController; | ||
final _focusNode = FocusNode(); | ||
String _walletName = ''; | ||
String? errorText; | ||
String? defaultWalletName; | ||
bool editName = false; | ||
|
||
void initState() { | ||
super.initState(); | ||
_nameController = TextEditingController(); | ||
_nameController.value = TextEditingValue( | ||
text: Locator.instance | ||
.get<ApiDatabase>() | ||
.walletStorage | ||
.currentWallet | ||
.name); | ||
_walletName = _nameController.value.text; | ||
defaultWalletName = | ||
"wallet-${Locator.instance.get<ApiDatabase>().walletStorage.wallets.length + 1}"; | ||
} | ||
|
||
Widget buildNameInputOrText(theme) { | ||
IconButton editNameBtn = IconButton( | ||
onPressed: () => {setState(() => editName = !editName)}, | ||
icon: Icon(FontAwesomeIcons.pen)); | ||
|
||
if (!editName) { | ||
return Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
Text(Locator.instance | ||
.get<ApiDatabase>() | ||
.walletStorage | ||
.currentWallet | ||
.name), | ||
editNameBtn, | ||
], | ||
); | ||
} | ||
|
||
void updateWalletName(String data) { | ||
Wallet _wallet = Locator.instance | ||
.get<ApiDatabase>() | ||
.walletStorage | ||
.currentWallet; | ||
setState(() { | ||
FocusManager.instance.primaryFocus?.unfocus(); | ||
_walletName = data; | ||
Locator.instance.get<ApiDatabase>().deleteWallet(_wallet); | ||
_wallet.name = _walletName; | ||
Locator.instance.get<ApiDatabase>().addWallet(_wallet); | ||
print(_wallet.jsonMap()); | ||
Locator.instance | ||
.get<ApiDatabase>() | ||
.walletStorage | ||
.setCurrentWallet(_wallet.id); | ||
editName = false; | ||
}); | ||
BlocProvider.of<DashboardBloc>(context).add( | ||
DashboardUpdateWalletEvent( | ||
currentWallet: _wallet, | ||
currentAddress: Locator.instance.get<ApiDatabase>().walletStorage.currentAccount.address)); | ||
} | ||
return Row( | ||
mainAxisSize: MainAxisSize.min, | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Flexible( | ||
child: TextField( | ||
autofocus: true, | ||
style: theme.textTheme.bodyText1, | ||
decoration: InputDecoration( | ||
hintText: localization.walletNameHint, | ||
errorText: errorText, | ||
), | ||
controller: _nameController, | ||
focusNode: _focusNode, | ||
onSubmitted: updateWalletName, | ||
onChanged: (String value) { | ||
setState(() { | ||
_walletName = value; | ||
}); | ||
}, | ||
), | ||
), | ||
editNameBtn, | ||
]); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
return Column( | ||
mainAxisSize: MainAxisSize.max, | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Text("Edit Wallet Name", | ||
style: theme.textTheme.titleMedium, | ||
), | ||
SizedBox(height: 8), | ||
buildNameInputOrText(theme), | ||
SizedBox(height: 16), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters