From 7ea025f9f0380428609fd7042f0191487b7134cd Mon Sep 17 00:00:00 2001 From: Elias Bonnici Date: Thu, 14 Dec 2023 17:21:46 +0100 Subject: [PATCH] Add `AppInputDecoration` to `AppTextFormField`. --- lib/fido/views/add_fingerprint_dialog.dart | 3 +- lib/fido/views/pin_dialog.dart | 113 +++++++----------- lib/fido/views/rename_fingerprint_dialog.dart | 3 +- lib/oath/views/oath_screen.dart | 3 +- lib/oath/views/rename_account_dialog.dart | 5 +- lib/piv/views/manage_key_dialog.dart | 46 +++---- lib/widgets/app_text_form_field.dart | 6 +- 7 files changed, 73 insertions(+), 106 deletions(-) diff --git a/lib/fido/views/add_fingerprint_dialog.dart b/lib/fido/views/add_fingerprint_dialog.dart index 2b1a556e..bcf82110 100755 --- a/lib/fido/views/add_fingerprint_dialog.dart +++ b/lib/fido/views/add_fingerprint_dialog.dart @@ -28,6 +28,7 @@ import '../../app/message.dart'; import '../../app/models.dart'; import '../../desktop/models.dart'; import '../../fido/models.dart'; +import '../../widgets/app_text_field.dart'; import '../../widgets/app_text_form_field.dart'; import '../../widgets/responsive_dialog.dart'; import '../../widgets/utf8_utils.dart'; @@ -206,7 +207,7 @@ class _AddFingerprintDialogState extends ConsumerState inputFormatters: [limitBytesLength(15)], buildCounter: buildByteCounterFor(_label), autofocus: true, - decoration: InputDecoration( + decoration: AppInputDecoration( enabled: _fingerprint != null, border: const OutlineInputBorder(), labelText: l10n.s_name, diff --git a/lib/fido/views/pin_dialog.dart b/lib/fido/views/pin_dialog.dart index 33fd37f5..88617421 100755 --- a/lib/fido/views/pin_dialog.dart +++ b/lib/fido/views/pin_dialog.dart @@ -24,6 +24,7 @@ import '../../app/message.dart'; import '../../app/models.dart'; import '../../app/state.dart'; import '../../desktop/models.dart'; +import '../../widgets/app_text_field.dart'; import '../../widgets/app_text_form_field.dart'; import '../../widgets/responsive_dialog.dart'; import '../models.dart'; @@ -81,36 +82,25 @@ class _FidoPinDialogState extends ConsumerState { autofocus: true, obscureText: _isObscureCurrent, autofillHints: const [AutofillHints.password], - decoration: InputDecoration( - border: const OutlineInputBorder(), - labelText: l10n.s_current_pin, - errorText: _currentIsWrong ? _currentPinError : null, - errorMaxLines: 3, - prefixIcon: const Icon(Icons.pin_outlined), - suffixIcon: Wrap( - crossAxisAlignment: WrapCrossAlignment.center, - children: [ - IconButton( - icon: Icon(_isObscureCurrent - ? Icons.visibility - : Icons.visibility_off), - onPressed: () { - setState(() { - _isObscureCurrent = !_isObscureCurrent; - }); - }, - tooltip: _isObscureCurrent - ? l10n.s_show_pin - : l10n.s_hide_pin, - ), - if (_currentIsWrong) ...[ - const Icon(Icons.error_outlined), - const SizedBox( - width: 8.0, - ) - ] - ], - )), + decoration: AppInputDecoration( + border: const OutlineInputBorder(), + labelText: l10n.s_current_pin, + errorText: _currentIsWrong ? _currentPinError : null, + errorMaxLines: 3, + prefixIcon: const Icon(Icons.pin_outlined), + suffixIcon: IconButton( + icon: Icon(_isObscureCurrent + ? Icons.visibility + : Icons.visibility_off), + onPressed: () { + setState(() { + _isObscureCurrent = !_isObscureCurrent; + }); + }, + tooltip: + _isObscureCurrent ? l10n.s_show_pin : l10n.s_hide_pin, + ), + ), onChanged: (value) { setState(() { _currentIsWrong = false; @@ -126,35 +116,23 @@ class _FidoPinDialogState extends ConsumerState { autofocus: !hasPin, obscureText: _isObscureNew, autofillHints: const [AutofillHints.password], - decoration: InputDecoration( + decoration: AppInputDecoration( border: const OutlineInputBorder(), labelText: l10n.s_new_pin, enabled: !hasPin || _currentPin.isNotEmpty, errorText: _newIsWrong ? _newPinError : null, errorMaxLines: 3, prefixIcon: const Icon(Icons.pin_outlined), - suffixIcon: Wrap( - crossAxisAlignment: WrapCrossAlignment.center, - children: [ - IconButton( - icon: Icon(_isObscureNew - ? Icons.visibility - : Icons.visibility_off), - onPressed: () { - setState(() { - _isObscureNew = !_isObscureNew; - }); - }, - tooltip: - _isObscureNew ? l10n.s_show_pin : l10n.s_hide_pin, - ), - if (_newIsWrong) ...[ - const Icon(Icons.error_outlined), - const SizedBox( - width: 8.0, - ) - ] - ]), + suffixIcon: IconButton( + icon: Icon( + _isObscureNew ? Icons.visibility : Icons.visibility_off), + onPressed: () { + setState(() { + _isObscureNew = !_isObscureNew; + }); + }, + tooltip: _isObscureNew ? l10n.s_show_pin : l10n.s_hide_pin, + ), ), onChanged: (value) { setState(() { @@ -167,26 +145,21 @@ class _FidoPinDialogState extends ConsumerState { initialValue: _confirmPin, obscureText: _isObscureConfirm, autofillHints: const [AutofillHints.password], - decoration: InputDecoration( + decoration: AppInputDecoration( border: const OutlineInputBorder(), labelText: l10n.s_confirm_pin, prefixIcon: const Icon(Icons.pin_outlined), - suffixIcon: Wrap( - crossAxisAlignment: WrapCrossAlignment.center, - children: [ - IconButton( - icon: Icon(_isObscureConfirm - ? Icons.visibility - : Icons.visibility_off), - onPressed: () { - setState(() { - _isObscureConfirm = !_isObscureConfirm; - }); - }, - tooltip: - _isObscureConfirm ? l10n.s_show_pin : l10n.s_hide_pin, - ) - ], + suffixIcon: IconButton( + icon: Icon(_isObscureConfirm + ? Icons.visibility + : Icons.visibility_off), + onPressed: () { + setState(() { + _isObscureConfirm = !_isObscureConfirm; + }); + }, + tooltip: + _isObscureConfirm ? l10n.s_show_pin : l10n.s_hide_pin, ), enabled: (!hasPin || _currentPin.isNotEmpty) && _newPin.isNotEmpty, diff --git a/lib/fido/views/rename_fingerprint_dialog.dart b/lib/fido/views/rename_fingerprint_dialog.dart index aead748c..240b1db5 100755 --- a/lib/fido/views/rename_fingerprint_dialog.dart +++ b/lib/fido/views/rename_fingerprint_dialog.dart @@ -21,6 +21,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../app/message.dart'; import '../../app/models.dart'; import '../../desktop/models.dart'; +import '../../widgets/app_text_field.dart'; import '../../widgets/app_text_form_field.dart'; import '../../widgets/responsive_dialog.dart'; import '../../widgets/utf8_utils.dart'; @@ -95,7 +96,7 @@ class _RenameAccountDialogState extends ConsumerState { maxLength: 15, inputFormatters: [limitBytesLength(15)], buildCounter: buildByteCounterFor(_label), - decoration: InputDecoration( + decoration: AppInputDecoration( border: const OutlineInputBorder(), labelText: l10n.s_label, prefixIcon: const Icon(Icons.fingerprint_outlined), diff --git a/lib/oath/views/oath_screen.dart b/lib/oath/views/oath_screen.dart index 26efcccb..197521f9 100755 --- a/lib/oath/views/oath_screen.dart +++ b/lib/oath/views/oath_screen.dart @@ -26,6 +26,7 @@ import '../../app/views/app_page.dart'; import '../../app/views/graphics.dart'; import '../../app/views/message_page.dart'; import '../../core/state.dart'; +import '../../widgets/app_text_field.dart'; import '../../widgets/app_text_form_field.dart'; import '../features.dart' as features; import '../keys.dart' as keys; @@ -161,7 +162,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> { // Use the default style, but with a smaller font size: style: textTheme.titleMedium ?.copyWith(fontSize: textTheme.titleSmall?.fontSize), - decoration: InputDecoration( + decoration: AppInputDecoration( hintText: l10n.s_search_accounts, border: const OutlineInputBorder( borderRadius: BorderRadius.all(Radius.circular(32)), diff --git a/lib/oath/views/rename_account_dialog.dart b/lib/oath/views/rename_account_dialog.dart index 3dfc236c..0d773f87 100755 --- a/lib/oath/views/rename_account_dialog.dart +++ b/lib/oath/views/rename_account_dialog.dart @@ -25,6 +25,7 @@ import '../../app/models.dart'; import '../../app/state.dart'; import '../../desktop/models.dart'; import '../../exception/cancellation_exception.dart'; +import '../../widgets/app_text_field.dart'; import '../../widgets/app_text_form_field.dart'; import '../../widgets/focus_utils.dart'; import '../../widgets/responsive_dialog.dart'; @@ -179,7 +180,7 @@ class _RenameAccountDialogState extends ConsumerState { buildCounter: buildByteCounterFor(_issuer), inputFormatters: [limitBytesLength(issuerRemaining)], key: keys.issuerField, - decoration: InputDecoration( + decoration: AppInputDecoration( border: const OutlineInputBorder(), labelText: l10n.s_issuer_optional, helperText: '', // Prevents dialog resizing when disabled @@ -198,7 +199,7 @@ class _RenameAccountDialogState extends ConsumerState { inputFormatters: [limitBytesLength(nameRemaining)], buildCounter: buildByteCounterFor(_name), key: keys.nameField, - decoration: InputDecoration( + decoration: AppInputDecoration( border: const OutlineInputBorder(), labelText: l10n.s_account_name, helperText: '', // Prevents dialog resizing when disabled diff --git a/lib/piv/views/manage_key_dialog.dart b/lib/piv/views/manage_key_dialog.dart index 53cf57df..dff55966 100644 --- a/lib/piv/views/manage_key_dialog.dart +++ b/lib/piv/views/manage_key_dialog.dart @@ -210,7 +210,7 @@ class _ManageKeyDialogState extends ConsumerState { controller: _currentController, readOnly: _defaultKeyUsed, maxLength: !_defaultKeyUsed ? currentType.keyLength * 2 : null, - decoration: InputDecoration( + decoration: AppInputDecoration( border: const OutlineInputBorder(), labelText: l10n.s_current_management_key, helperText: _defaultKeyUsed ? l10n.l_default_key_used : null, @@ -229,34 +229,22 @@ class _ManageKeyDialogState extends ConsumerState { : (_hasMetadata && _currentIsWrong || _currentInvalidFormat) ? const Icon(Icons.error) - : Wrap( - crossAxisAlignment: WrapCrossAlignment.center, - children: [ - IconButton( - icon: Icon(_defaultKeyUsed - ? Icons.auto_awesome - : Icons.auto_awesome_outlined), - tooltip: l10n.s_use_default, - onPressed: () { - setState(() { - _defaultKeyUsed = !_defaultKeyUsed; - if (_defaultKeyUsed) { - _currentController.text = - defaultManagementKey; - } else { - _currentController.clear(); - } - }); - }, - ), - if (_currentIsWrong || - _currentInvalidFormat) ...[ - const Icon(Icons.error_outlined), - const SizedBox( - width: 8.0, - ) - ] - ], + : IconButton( + icon: Icon(_defaultKeyUsed + ? Icons.auto_awesome + : Icons.auto_awesome_outlined), + tooltip: l10n.s_use_default, + onPressed: () { + setState(() { + _defaultKeyUsed = !_defaultKeyUsed; + if (_defaultKeyUsed) { + _currentController.text = + defaultManagementKey; + } else { + _currentController.clear(); + } + }); + }, ), ), textInputAction: TextInputAction.next, diff --git a/lib/widgets/app_text_form_field.dart b/lib/widgets/app_text_form_field.dart index ea9020df..7e4b395b 100644 --- a/lib/widgets/app_text_form_field.dart +++ b/lib/widgets/app_text_form_field.dart @@ -16,6 +16,8 @@ import 'package:flutter/material.dart'; +import 'app_text_field.dart'; + /// TextFormField without autocorrect and suggestions class AppTextFormField extends TextFormField { AppTextFormField({ @@ -28,7 +30,7 @@ class AppTextFormField extends TextFormField { super.controller, super.initialValue, super.focusNode, - super.decoration, + AppInputDecoration? decoration, super.textCapitalization, super.textInputAction, super.style, @@ -87,5 +89,5 @@ class AppTextFormField extends TextFormField { super.clipBehavior, super.scribbleEnabled, super.canRequestFocus, - }); + }) : super(decoration: decoration); }