Skip to content

Commit

Permalink
Remove AppTextFormField
Browse files Browse the repository at this point in the history
AppTextFormField is mainly meant to be used in a Form widget. However, we
never use it that way which is the reason for deleting it. We can
achieve the same functionality with AppTextField.
  • Loading branch information
elibon99 committed Jan 9, 2025
1 parent ebf2689 commit 2157780
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 195 deletions.
6 changes: 3 additions & 3 deletions lib/fido/views/add_fingerprint_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import '../../app/models.dart';
import '../../desktop/models.dart';
import '../../fido/models.dart';
import '../../widgets/app_input_decoration.dart';
import '../../widgets/app_text_form_field.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/responsive_dialog.dart';
import '../../widgets/utf8_utils.dart';
import '../state.dart';
Expand Down Expand Up @@ -240,7 +240,7 @@ class _AddFingerprintDialogState extends ConsumerState<AddFingerprintDialog>
const SizedBox(height: 16),
Container(
constraints: const BoxConstraints(maxWidth: 360),
child: AppTextFormField(
child: AppTextField(
focusNode: _nameFocus,
maxLength: 15,
inputFormatters: [limitBytesLength(15)],
Expand All @@ -256,7 +256,7 @@ class _AddFingerprintDialogState extends ConsumerState<AddFingerprintDialog>
_label = value.trim();
});
},
onFieldSubmitted: (_) {
onSubmitted: (_) {
if (_label.isNotEmpty) {
_submit();
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/fido/views/passkeys_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import '../../core/state.dart';
import '../../exception/no_data_exception.dart';
import '../../management/models.dart';
import '../../widgets/app_input_decoration.dart';
import '../../widgets/app_text_form_field.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/flex_box.dart';
import '../../widgets/list_title.dart';
import '../features.dart' as features;
Expand Down Expand Up @@ -401,7 +401,7 @@ class _FidoUnlockedPageState extends ConsumerState<_FidoUnlockedPage> {
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10.0, vertical: 8.0),
child: AppTextFormField(
child: AppTextField(
key: searchField,
controller: searchController,
canRequestFocus: _canRequestFocus,
Expand Down Expand Up @@ -538,7 +538,7 @@ class _FidoUnlockedPageState extends ConsumerState<_FidoUnlockedPage> {
setState(() {});
},
textInputAction: TextInputAction.next,
onFieldSubmitted: (value) {
onSubmitted: (value) {
Focus.of(context)
.focusInDirection(TraversalDirection.down);
},
Expand Down
36 changes: 17 additions & 19 deletions lib/fido/views/pin_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import '../../desktop/models.dart';
import '../../exception/cancellation_exception.dart';
import '../../management/models.dart';
import '../../widgets/app_input_decoration.dart';
import '../../widgets/app_text_form_field.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/responsive_dialog.dart';
import '../../widgets/utf8_utils.dart';
import '../keys.dart';
Expand All @@ -52,8 +52,8 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
final _currentPinFocus = FocusNode();
final _newPinController = TextEditingController();
final _newPinFocus = FocusNode();
final _confirmPinController = TextEditingController();
final _confirmPinFocus = FocusNode();
String _confirmPin = '';
String? _currentPinError;
String? _newPinError;
bool _currentIsWrong = false;
Expand Down Expand Up @@ -87,7 +87,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
final newPinLenOk = _newPinController.text.length >= minPinLength;
final isValid = currentPinLenOk &&
newPinLenOk &&
_newPinController.text == _confirmPin &&
_newPinController.text == _confirmPinController.text &&
!_currentIsWrong;

final newPinEnabled = !_isBlocked && currentPinLenOk;
Expand Down Expand Up @@ -122,7 +122,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
children: [
if (hasPin) ...[
Text(l10n.p_enter_current_pin_or_reset_no_puk),
AppTextFormField(
AppTextField(
key: currentPin,
controller: _currentPinController,
focusNode: _currentPinFocus,
Expand Down Expand Up @@ -161,7 +161,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
_currentIsWrong = false;
});
},
onFieldSubmitted: (_) {
onSubmitted: (_) {
if (_currentPinController.text.length < minPinLength) {
_currentPinFocus.requestFocus();
} else {
Expand All @@ -174,7 +174,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
? l10n.p_enter_new_fido2_pin_complexity_active(
minPinLength, maxPinLength, 2, '123456')
: l10n.p_enter_new_fido2_pin(minPinLength, maxPinLength)),
AppTextFormField(
AppTextField(
key: newPin,
controller: _newPinController,
focusNode: _newPinFocus,
Expand Down Expand Up @@ -212,21 +212,21 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
_newIsWrong = false;
});
},
onFieldSubmitted: (_) {
onSubmitted: (_) {
if (_newPinController.text.length < minPinLength) {
_newPinFocus.requestFocus();
} else {
_confirmPinFocus.requestFocus();
}
},
).init(),
AppTextFormField(
AppTextField(
key: confirmPin,
initialValue: _confirmPin,
controller: _confirmPinController,
focusNode: _confirmPinFocus,
maxLength: maxPinLength,
inputFormatters: [limitBytesLength(maxPinLength)],
buildCounter: buildByteCounterFor(_confirmPin),
buildCounter: buildByteCounterFor(_confirmPinController.text),
obscureText: _isObscureConfirm,
autofillHints: const [AutofillHints.password],
decoration: AppInputDecoration(
Expand All @@ -249,20 +249,18 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
),
),
enabled: confirmPinEnabled,
errorText:
_newPinController.text.length == _confirmPin.length &&
_newPinController.text != _confirmPin
? l10n.l_pin_mismatch
: null,
errorText: _newPinController.text.length ==
_confirmPinController.text.length &&
_newPinController.text != _confirmPinController.text
? l10n.l_pin_mismatch
: null,
helperText: '', // Prevents resizing when errorText shown
),
textInputAction: TextInputAction.done,
onChanged: (value) {
setState(() {
_confirmPin = value;
});
setState(() {});
},
onFieldSubmitted: (_) {
onSubmitted: (_) {
if (isValid) {
_submit();
} else {
Expand Down
27 changes: 13 additions & 14 deletions lib/fido/views/rename_fingerprint_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import '../../app/message.dart';
import '../../app/models.dart';
import '../../desktop/models.dart';
import '../../widgets/app_input_decoration.dart';
import '../../widgets/app_text_form_field.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/responsive_dialog.dart';
import '../../widgets/utf8_utils.dart';
import '../models.dart';
Expand All @@ -40,14 +40,14 @@ class RenameFingerprintDialog extends ConsumerStatefulWidget {
}

class _RenameAccountDialogState extends ConsumerState<RenameFingerprintDialog> {
late String _label;
late TextEditingController _labelController;
late FocusNode _labelFocus;
_RenameAccountDialogState();

@override
void initState() {
super.initState();
_label = widget.fingerprint.name ?? '';
_labelController = TextEditingController(text: widget.fingerprint.name);
_labelFocus = FocusNode();
}

Expand All @@ -62,7 +62,7 @@ class _RenameAccountDialogState extends ConsumerState<RenameFingerprintDialog> {
try {
final renamed = await ref
.read(fingerprintProvider(widget.devicePath).notifier)
.renameFingerprint(widget.fingerprint, _label);
.renameFingerprint(widget.fingerprint, _labelController.text.trim());
if (!mounted) return;
Navigator.of(context).pop(renamed);
showMessage(context, l10n.s_fingerprint_renamed);
Expand All @@ -85,11 +85,12 @@ class _RenameAccountDialogState extends ConsumerState<RenameFingerprintDialog> {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final label = _labelController.text.trim();
return ResponsiveDialog(
title: Text(l10n.s_rename_fp),
actions: [
TextButton(
onPressed: _label.isNotEmpty ? _submit : null,
onPressed: label.isNotEmpty ? _submit : null,
child: Text(l10n.s_save),
),
],
Expand All @@ -100,25 +101,23 @@ class _RenameAccountDialogState extends ConsumerState<RenameFingerprintDialog> {
children: [
Text(l10n.q_rename_target(widget.fingerprint.label)),
Text(l10n.p_will_change_label_fp),
AppTextFormField(
AppTextField(
autofocus: true,
initialValue: _label,
controller: _labelController,
focusNode: _labelFocus,
maxLength: 15,
inputFormatters: [limitBytesLength(15)],
buildCounter: buildByteCounterFor(_label),
buildCounter: buildByteCounterFor(label),
decoration: AppInputDecoration(
border: const OutlineInputBorder(),
labelText: l10n.s_name,
prefixIcon: const Icon(Symbols.fingerprint),
),
onChanged: (value) {
setState(() {
_label = value.trim();
});
onChanged: (_) {
setState(() {});
},
onFieldSubmitted: (_) {
if (_label.isNotEmpty) {
onSubmitted: (_) {
if (label.isNotEmpty) {
_submit();
} else {
_labelFocus.requestFocus();
Expand Down
26 changes: 14 additions & 12 deletions lib/home/views/manage_label_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'package:material_symbols_icons/symbols.dart';
import '../../app/models.dart';
import '../../app/state.dart';
import '../../widgets/app_input_decoration.dart';
import '../../widgets/app_text_form_field.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/focus_utils.dart';
import '../../widgets/responsive_dialog.dart';

Expand All @@ -36,19 +36,22 @@ class ManageLabelDialog extends ConsumerStatefulWidget {
}

class _ManageLabelDialogState extends ConsumerState<ManageLabelDialog> {
String? _label;
late TextEditingController _labelController;

@override
void initState() {
super.initState();
_label = widget.initialCustomization.name;
_labelController =
TextEditingController(text: widget.initialCustomization.name);
}

@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final initialLabel = widget.initialCustomization.name;
final didChange = initialLabel != _label;
final trimmed = _labelController.text.trim();
final label = trimmed.isEmpty ? null : trimmed;
final didChange = initialLabel != label;
return ResponsiveDialog(
title:
Text(initialLabel != null ? l10n.s_change_label : l10n.s_set_label),
Expand All @@ -67,9 +70,9 @@ class _ManageLabelDialogState extends ConsumerState<ManageLabelDialog> {
Text(initialLabel == null
? l10n.p_set_will_add_custom_name
: l10n.p_rename_will_change_custom_name),
AppTextFormField(
AppTextField(
autofocus: true,
initialValue: _label,
controller: _labelController,
maxLength: 20,
decoration: AppInputDecoration(
border: const OutlineInputBorder(),
Expand All @@ -79,12 +82,9 @@ class _ManageLabelDialogState extends ConsumerState<ManageLabelDialog> {
),
textInputAction: TextInputAction.done,
onChanged: (value) {
setState(() {
final trimmed = value.trim();
_label = trimmed.isEmpty ? null : trimmed;
});
setState(() {});
},
onFieldSubmitted: (_) {
onSubmitted: (_) {
_submit();
},
).init()
Expand All @@ -101,9 +101,11 @@ class _ManageLabelDialogState extends ConsumerState<ManageLabelDialog> {

void _submit() async {
final manager = ref.read(keyCustomizationManagerProvider.notifier);
final trimmed = _labelController.text.trim();
final label = trimmed.isEmpty ? null : trimmed;
await manager.set(
serial: widget.initialCustomization.serial,
name: _label,
name: label,
color: widget.initialCustomization.color);

await ref.read(withContextProvider)((context) async {
Expand Down
6 changes: 3 additions & 3 deletions lib/oath/views/oath_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import '../../core/state.dart';
import '../../exception/no_data_exception.dart';
import '../../management/models.dart';
import '../../widgets/app_input_decoration.dart';
import '../../widgets/app_text_form_field.dart';
import '../../widgets/app_text_field.dart';
import '../../widgets/file_drop_overlay.dart';
import '../../widgets/list_title.dart';
import '../../widgets/tooltip_if_truncated.dart';
Expand Down Expand Up @@ -446,7 +446,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10.0, vertical: 8.0),
child: AppTextFormField(
child: AppTextField(
key: searchField,
controller: searchController,
canRequestFocus: _canRequestFocus,
Expand Down Expand Up @@ -583,7 +583,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
setState(() {});
},
textInputAction: TextInputAction.next,
onFieldSubmitted: (value) {
onSubmitted: (value) {
Focus.of(context)
.focusInDirection(TraversalDirection.down);
},
Expand Down
Loading

0 comments on commit 2157780

Please sign in to comment.