Skip to content

Commit

Permalink
refactor: move localization to class method
Browse files Browse the repository at this point in the history
  • Loading branch information
parodyBit committed Aug 29, 2023
1 parent e9936c7 commit 91aeb4f
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions lib/screens/create_wallet/encrypt_wallet_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,35 @@ class EncryptWalletCardState extends State<EncryptWalletCard>
super.dispose();
}

List<Widget> buildLocalizedTextBlock(BuildContext context) {
final theme = Theme.of(context);
Map<int, String> _encryptWalletTextLocalization(BuildContext context) => {
0: AppLocalizations.of(context)!.encryptWalletHeader,
1: AppLocalizations.of(context)!.encryptWallet01,
2: AppLocalizations.of(context)!.encryptWallet02,
3: AppLocalizations.of(context)!.encryptWallet03(Locator.instance
.get<ApiCreateWallet>()
.seedData!
.split(' ')
.length),
};
List<Widget> _widgets = [];
List<String> _localization =
_encryptWalletTextLocalization(context).values.toList();

// for each item, add a text widget and a spacer SizedBox
// if it is the first item, set the text style for a header
_encryptWalletTextLocalization(context).forEach((key, value) {
_widgets.add(Text(
_localization[key],
style:
key == 0 ? theme.textTheme.titleLarge : theme.textTheme.bodyLarge,
));
_widgets.add(SizedBox(height: 8));
});
return _widgets;
}

@override
Widget build(BuildContext context) {
_passConfirmFocusNode.addListener(() => validateForm());
Expand All @@ -140,30 +169,8 @@ class EncryptWalletCardState extends State<EncryptWalletCard>
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppLocalizations.of(context)!.encryptWalletHeader,
style: theme.textTheme.titleLarge,
),
...buildLocalizedTextBlock(context),
SizedBox(height: 8),
Text(
AppLocalizations.of(context)!.encryptWallet01,
style: theme.textTheme.bodyLarge,
),
SizedBox(height: 8),
Text(
AppLocalizations.of(context)!.encryptWallet02,
style: theme.textTheme.bodyLarge,
),
SizedBox(height: 8),
Text(
AppLocalizations.of(context)!.encryptWallet03(Locator.instance
.get<ApiCreateWallet>()
.seedData!
.split(' ')
.length),
style: theme.textTheme.bodyLarge,
),
SizedBox(height: 16),
Form(
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(
Expand Down

0 comments on commit 91aeb4f

Please sign in to comment.