Add AppInputDecoration to AppTextFormField.

This commit is contained in:
Elias Bonnici 2023-12-14 17:21:46 +01:00
parent a7f6284dd7
commit 7ea025f9f0
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF
7 changed files with 73 additions and 106 deletions

View File

@ -28,6 +28,7 @@ import '../../app/message.dart';
import '../../app/models.dart'; import '../../app/models.dart';
import '../../desktop/models.dart'; import '../../desktop/models.dart';
import '../../fido/models.dart'; import '../../fido/models.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/app_text_form_field.dart'; import '../../widgets/app_text_form_field.dart';
import '../../widgets/responsive_dialog.dart'; import '../../widgets/responsive_dialog.dart';
import '../../widgets/utf8_utils.dart'; import '../../widgets/utf8_utils.dart';
@ -206,7 +207,7 @@ class _AddFingerprintDialogState extends ConsumerState<AddFingerprintDialog>
inputFormatters: [limitBytesLength(15)], inputFormatters: [limitBytesLength(15)],
buildCounter: buildByteCounterFor(_label), buildCounter: buildByteCounterFor(_label),
autofocus: true, autofocus: true,
decoration: InputDecoration( decoration: AppInputDecoration(
enabled: _fingerprint != null, enabled: _fingerprint != null,
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
labelText: l10n.s_name, labelText: l10n.s_name,

View File

@ -24,6 +24,7 @@ import '../../app/message.dart';
import '../../app/models.dart'; import '../../app/models.dart';
import '../../app/state.dart'; import '../../app/state.dart';
import '../../desktop/models.dart'; import '../../desktop/models.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/app_text_form_field.dart'; import '../../widgets/app_text_form_field.dart';
import '../../widgets/responsive_dialog.dart'; import '../../widgets/responsive_dialog.dart';
import '../models.dart'; import '../models.dart';
@ -81,16 +82,13 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
autofocus: true, autofocus: true,
obscureText: _isObscureCurrent, obscureText: _isObscureCurrent,
autofillHints: const [AutofillHints.password], autofillHints: const [AutofillHints.password],
decoration: InputDecoration( decoration: AppInputDecoration(
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
labelText: l10n.s_current_pin, labelText: l10n.s_current_pin,
errorText: _currentIsWrong ? _currentPinError : null, errorText: _currentIsWrong ? _currentPinError : null,
errorMaxLines: 3, errorMaxLines: 3,
prefixIcon: const Icon(Icons.pin_outlined), prefixIcon: const Icon(Icons.pin_outlined),
suffixIcon: Wrap( suffixIcon: IconButton(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
IconButton(
icon: Icon(_isObscureCurrent icon: Icon(_isObscureCurrent
? Icons.visibility ? Icons.visibility
: Icons.visibility_off), : Icons.visibility_off),
@ -99,18 +97,10 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
_isObscureCurrent = !_isObscureCurrent; _isObscureCurrent = !_isObscureCurrent;
}); });
}, },
tooltip: _isObscureCurrent tooltip:
? l10n.s_show_pin _isObscureCurrent ? l10n.s_show_pin : l10n.s_hide_pin,
: l10n.s_hide_pin, ),
), ),
if (_currentIsWrong) ...[
const Icon(Icons.error_outlined),
const SizedBox(
width: 8.0,
)
]
],
)),
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
_currentIsWrong = false; _currentIsWrong = false;
@ -126,35 +116,23 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
autofocus: !hasPin, autofocus: !hasPin,
obscureText: _isObscureNew, obscureText: _isObscureNew,
autofillHints: const [AutofillHints.password], autofillHints: const [AutofillHints.password],
decoration: InputDecoration( decoration: AppInputDecoration(
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
labelText: l10n.s_new_pin, labelText: l10n.s_new_pin,
enabled: !hasPin || _currentPin.isNotEmpty, enabled: !hasPin || _currentPin.isNotEmpty,
errorText: _newIsWrong ? _newPinError : null, errorText: _newIsWrong ? _newPinError : null,
errorMaxLines: 3, errorMaxLines: 3,
prefixIcon: const Icon(Icons.pin_outlined), prefixIcon: const Icon(Icons.pin_outlined),
suffixIcon: Wrap( suffixIcon: IconButton(
crossAxisAlignment: WrapCrossAlignment.center, icon: Icon(
children: [ _isObscureNew ? Icons.visibility : Icons.visibility_off),
IconButton(
icon: Icon(_isObscureNew
? Icons.visibility
: Icons.visibility_off),
onPressed: () { onPressed: () {
setState(() { setState(() {
_isObscureNew = !_isObscureNew; _isObscureNew = !_isObscureNew;
}); });
}, },
tooltip: tooltip: _isObscureNew ? l10n.s_show_pin : l10n.s_hide_pin,
_isObscureNew ? l10n.s_show_pin : l10n.s_hide_pin,
), ),
if (_newIsWrong) ...[
const Icon(Icons.error_outlined),
const SizedBox(
width: 8.0,
)
]
]),
), ),
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
@ -167,14 +145,11 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
initialValue: _confirmPin, initialValue: _confirmPin,
obscureText: _isObscureConfirm, obscureText: _isObscureConfirm,
autofillHints: const [AutofillHints.password], autofillHints: const [AutofillHints.password],
decoration: InputDecoration( decoration: AppInputDecoration(
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
labelText: l10n.s_confirm_pin, labelText: l10n.s_confirm_pin,
prefixIcon: const Icon(Icons.pin_outlined), prefixIcon: const Icon(Icons.pin_outlined),
suffixIcon: Wrap( suffixIcon: IconButton(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
IconButton(
icon: Icon(_isObscureConfirm icon: Icon(_isObscureConfirm
? Icons.visibility ? Icons.visibility
: Icons.visibility_off), : Icons.visibility_off),
@ -185,8 +160,6 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
}, },
tooltip: tooltip:
_isObscureConfirm ? l10n.s_show_pin : l10n.s_hide_pin, _isObscureConfirm ? l10n.s_show_pin : l10n.s_hide_pin,
)
],
), ),
enabled: enabled:
(!hasPin || _currentPin.isNotEmpty) && _newPin.isNotEmpty, (!hasPin || _currentPin.isNotEmpty) && _newPin.isNotEmpty,

View File

@ -21,6 +21,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../app/message.dart'; import '../../app/message.dart';
import '../../app/models.dart'; import '../../app/models.dart';
import '../../desktop/models.dart'; import '../../desktop/models.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/app_text_form_field.dart'; import '../../widgets/app_text_form_field.dart';
import '../../widgets/responsive_dialog.dart'; import '../../widgets/responsive_dialog.dart';
import '../../widgets/utf8_utils.dart'; import '../../widgets/utf8_utils.dart';
@ -95,7 +96,7 @@ class _RenameAccountDialogState extends ConsumerState<RenameFingerprintDialog> {
maxLength: 15, maxLength: 15,
inputFormatters: [limitBytesLength(15)], inputFormatters: [limitBytesLength(15)],
buildCounter: buildByteCounterFor(_label), buildCounter: buildByteCounterFor(_label),
decoration: InputDecoration( decoration: AppInputDecoration(
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
labelText: l10n.s_label, labelText: l10n.s_label,
prefixIcon: const Icon(Icons.fingerprint_outlined), prefixIcon: const Icon(Icons.fingerprint_outlined),

View File

@ -26,6 +26,7 @@ import '../../app/views/app_page.dart';
import '../../app/views/graphics.dart'; import '../../app/views/graphics.dart';
import '../../app/views/message_page.dart'; import '../../app/views/message_page.dart';
import '../../core/state.dart'; import '../../core/state.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/app_text_form_field.dart'; import '../../widgets/app_text_form_field.dart';
import '../features.dart' as features; import '../features.dart' as features;
import '../keys.dart' as keys; import '../keys.dart' as keys;
@ -161,7 +162,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
// Use the default style, but with a smaller font size: // Use the default style, but with a smaller font size:
style: textTheme.titleMedium style: textTheme.titleMedium
?.copyWith(fontSize: textTheme.titleSmall?.fontSize), ?.copyWith(fontSize: textTheme.titleSmall?.fontSize),
decoration: InputDecoration( decoration: AppInputDecoration(
hintText: l10n.s_search_accounts, hintText: l10n.s_search_accounts,
border: const OutlineInputBorder( border: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(32)), borderRadius: BorderRadius.all(Radius.circular(32)),

View File

@ -25,6 +25,7 @@ import '../../app/models.dart';
import '../../app/state.dart'; import '../../app/state.dart';
import '../../desktop/models.dart'; import '../../desktop/models.dart';
import '../../exception/cancellation_exception.dart'; import '../../exception/cancellation_exception.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/app_text_form_field.dart'; import '../../widgets/app_text_form_field.dart';
import '../../widgets/focus_utils.dart'; import '../../widgets/focus_utils.dart';
import '../../widgets/responsive_dialog.dart'; import '../../widgets/responsive_dialog.dart';
@ -179,7 +180,7 @@ class _RenameAccountDialogState extends ConsumerState<RenameAccountDialog> {
buildCounter: buildByteCounterFor(_issuer), buildCounter: buildByteCounterFor(_issuer),
inputFormatters: [limitBytesLength(issuerRemaining)], inputFormatters: [limitBytesLength(issuerRemaining)],
key: keys.issuerField, key: keys.issuerField,
decoration: InputDecoration( decoration: AppInputDecoration(
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
labelText: l10n.s_issuer_optional, labelText: l10n.s_issuer_optional,
helperText: '', // Prevents dialog resizing when disabled helperText: '', // Prevents dialog resizing when disabled
@ -198,7 +199,7 @@ class _RenameAccountDialogState extends ConsumerState<RenameAccountDialog> {
inputFormatters: [limitBytesLength(nameRemaining)], inputFormatters: [limitBytesLength(nameRemaining)],
buildCounter: buildByteCounterFor(_name), buildCounter: buildByteCounterFor(_name),
key: keys.nameField, key: keys.nameField,
decoration: InputDecoration( decoration: AppInputDecoration(
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
labelText: l10n.s_account_name, labelText: l10n.s_account_name,
helperText: '', // Prevents dialog resizing when disabled helperText: '', // Prevents dialog resizing when disabled

View File

@ -210,7 +210,7 @@ class _ManageKeyDialogState extends ConsumerState<ManageKeyDialog> {
controller: _currentController, controller: _currentController,
readOnly: _defaultKeyUsed, readOnly: _defaultKeyUsed,
maxLength: !_defaultKeyUsed ? currentType.keyLength * 2 : null, maxLength: !_defaultKeyUsed ? currentType.keyLength * 2 : null,
decoration: InputDecoration( decoration: AppInputDecoration(
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
labelText: l10n.s_current_management_key, labelText: l10n.s_current_management_key,
helperText: _defaultKeyUsed ? l10n.l_default_key_used : null, helperText: _defaultKeyUsed ? l10n.l_default_key_used : null,
@ -229,10 +229,7 @@ class _ManageKeyDialogState extends ConsumerState<ManageKeyDialog> {
: (_hasMetadata && _currentIsWrong || : (_hasMetadata && _currentIsWrong ||
_currentInvalidFormat) _currentInvalidFormat)
? const Icon(Icons.error) ? const Icon(Icons.error)
: Wrap( : IconButton(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
IconButton(
icon: Icon(_defaultKeyUsed icon: Icon(_defaultKeyUsed
? Icons.auto_awesome ? Icons.auto_awesome
: Icons.auto_awesome_outlined), : Icons.auto_awesome_outlined),
@ -249,15 +246,6 @@ class _ManageKeyDialogState extends ConsumerState<ManageKeyDialog> {
}); });
}, },
), ),
if (_currentIsWrong ||
_currentInvalidFormat) ...[
const Icon(Icons.error_outlined),
const SizedBox(
width: 8.0,
)
]
],
),
), ),
textInputAction: TextInputAction.next, textInputAction: TextInputAction.next,
onChanged: (value) { onChanged: (value) {

View File

@ -16,6 +16,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'app_text_field.dart';
/// TextFormField without autocorrect and suggestions /// TextFormField without autocorrect and suggestions
class AppTextFormField extends TextFormField { class AppTextFormField extends TextFormField {
AppTextFormField({ AppTextFormField({
@ -28,7 +30,7 @@ class AppTextFormField extends TextFormField {
super.controller, super.controller,
super.initialValue, super.initialValue,
super.focusNode, super.focusNode,
super.decoration, AppInputDecoration? decoration,
super.textCapitalization, super.textCapitalization,
super.textInputAction, super.textInputAction,
super.style, super.style,
@ -87,5 +89,5 @@ class AppTextFormField extends TextFormField {
super.clipBehavior, super.clipBehavior,
super.scribbleEnabled, super.scribbleEnabled,
super.canRequestFocus, super.canRequestFocus,
}); }) : super(decoration: decoration);
} }