Add init() to AppTextFields

This is ugly, but it allows wrapping the widgets for more customization.
This commit is contained in:
Dain Nilsson 2024-03-07 15:01:46 +01:00
parent 7942916df5
commit 3ee27bea96
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
21 changed files with 79 additions and 36 deletions

View File

@ -256,7 +256,7 @@ class _AddFingerprintDialogState extends ConsumerState<AddFingerprintDialog>
onFieldSubmitted: (_) {
_submit();
},
),
).init(),
)
]
],

View File

@ -126,7 +126,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
_currentIsWrong = false;
});
},
),
).init(),
],
Text(l10n.p_enter_new_fido2_pin(minPinLength)),
// TODO: Set max characters based on UTF-8 bytes
@ -161,7 +161,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
_newPin = value;
});
},
),
).init(),
AppTextFormField(
key: confirmPin,
initialValue: _confirmPin,
@ -200,7 +200,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
_submit();
}
},
),
).init(),
]
.map((e) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),

View File

@ -128,7 +128,7 @@ class _PinEntryFormState extends ConsumerState<PinEntryForm> {
});
}, // Update state on change
onSubmitted: (_) => _submit(),
),
).init(),
),
ListTile(
leading: noFingerprints

View File

@ -112,7 +112,7 @@ class _RenameAccountDialogState extends ConsumerState<RenameFingerprintDialog> {
_submit();
}
},
),
).init(),
]
.map((e) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),

View File

@ -390,7 +390,7 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
onSubmitted: (_) {
if (isValid) submit();
},
),
).init(),
AppTextField(
key: keys.nameField,
controller: _accountController,
@ -418,7 +418,7 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
onSubmitted: (_) {
if (isValid) submit();
},
),
).init(),
AppTextField(
key: keys.secretField,
controller: _secretController,
@ -460,7 +460,7 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
onSubmitted: (_) {
if (isValid) submit();
},
),
).init(),
const SizedBox(height: 8),
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,

View File

@ -137,7 +137,7 @@ class _ManagePasswordDialogState extends ConsumerState<ManagePasswordDialog> {
_currentIsWrong = false;
});
},
),
).init(),
Wrap(
spacing: 4.0,
runSpacing: 8.0,
@ -227,7 +227,7 @@ class _ManagePasswordDialogState extends ConsumerState<ManagePasswordDialog> {
_submit();
}
},
),
).init(),
AppTextField(
key: keys.confirmPasswordField,
obscureText: _isObscureConfirm,
@ -268,7 +268,7 @@ class _ManagePasswordDialogState extends ConsumerState<ManagePasswordDialog> {
_submit();
}
},
),
).init(),
]
.map((e) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),

View File

@ -439,7 +439,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
Focus.of(context)
.focusInDirection(TraversalDirection.down);
},
),
).init(),
);
}),
),

View File

@ -193,7 +193,7 @@ class _RenameAccountDialogState extends ConsumerState<RenameAccountDialog> {
_issuer = value.trim();
});
},
),
).init(),
AppTextFormField(
initialValue: _name,
maxLength: nameRemaining,
@ -222,7 +222,7 @@ class _RenameAccountDialogState extends ConsumerState<RenameAccountDialog> {
_submit();
}
},
),
).init(),
]
.map((e) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),

View File

@ -110,7 +110,7 @@ class _UnlockFormState extends ConsumerState<UnlockForm> {
_passwordIsWrong = false;
}), // Update state on change
onSubmitted: (_) => _submit(),
),
).init(),
),
const SizedBox(height: 3.0),
Column(

View File

@ -166,7 +166,7 @@ class _ConfigureChalrespDialogState
_validateSecret = false;
});
},
),
).init(),
FilterChip(
label: Text(l10n.s_require_touch),
selected: _requireTouch,

View File

@ -159,7 +159,7 @@ class _ConfigureHotpDialogState extends ConsumerState<ConfigureHotpDialog> {
_validateSecret = false;
});
},
),
).init(),
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 4.0,

View File

@ -181,7 +181,7 @@ class _ConfigureStaticDialogState extends ConsumerState<ConfigureStaticDialog> {
_validatePassword = false;
});
},
),
).init(),
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 4.0,

View File

@ -237,7 +237,7 @@ class _ConfigureYubiOtpDialogState
_validatePublicIdFormat = false;
});
},
),
).init(),
AppTextField(
key: keys.privateIdField,
controller: _privateIdController,
@ -274,7 +274,7 @@ class _ConfigureYubiOtpDialogState
_validatePrivateIdFormat = false;
});
},
),
).init(),
AppTextField(
key: keys.secretField,
controller: _secretController,
@ -311,7 +311,7 @@ class _ConfigureYubiOtpDialogState
_validateSecretFormat = false;
});
},
),
).init(),
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 4.0,

View File

@ -160,7 +160,7 @@ class _AuthenticationDialogState extends ConsumerState<AuthenticationDialog> {
_keyFormatInvalid = false;
});
},
),
).init(),
]
.map((e) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),

View File

@ -174,7 +174,7 @@ class _GenerateKeyDialogState extends ConsumerState<GenerateKeyDialog> {
_subject = value;
});
},
),
).init(),
Text(
l10n.rfc4514_examples,
style: subtitleStyle,

View File

@ -162,7 +162,7 @@ class _ImportFileDialogState extends ConsumerState<ImportFileDialog> {
});
},
onSubmitted: (_) => _examine(),
),
).init(),
]
.map((e) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),

View File

@ -226,7 +226,7 @@ class _ManageKeyDialogState extends ConsumerState<ManageKeyDialog> {
_currentInvalidFormat = false;
});
},
),
).init(),
if (!_usesStoredKey)
AppTextFormField(
key: keys.managementKeyField,
@ -272,7 +272,7 @@ class _ManageKeyDialogState extends ConsumerState<ManageKeyDialog> {
_currentIsWrong = false;
});
},
),
).init(),
AppTextField(
key: keys.newPinPukField,
autofocus: _defaultKeyUsed,
@ -320,7 +320,7 @@ class _ManageKeyDialogState extends ConsumerState<ManageKeyDialog> {
_submit();
}
},
),
).init(),
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 4.0,

View File

@ -207,7 +207,7 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
_currentIsWrong = false;
});
},
),
).init(),
Text(l10n.p_enter_new_piv_pin_puk(
widget.target == ManageTarget.puk ? l10n.s_puk : l10n.s_pin)),
AppTextField(
@ -248,7 +248,7 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
_submit();
}
},
),
).init(),
AppTextField(
key: keys.confirmPinPukField,
obscureText: _isObscureConfirm,
@ -293,7 +293,7 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
_submit();
}
},
),
).init(),
]
.map((e) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),

View File

@ -128,7 +128,7 @@ class _PinDialogState extends ConsumerState<PinDialog> {
});
},
onSubmitted: (_) => _submit(),
),
).init(),
]
.map((e) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),

View File

@ -14,13 +14,17 @@
* limitations under the License.
*/
import 'dart:async';
import 'package:flutter/material.dart';
import 'app_input_decoration.dart';
/// TextField without autocorrect and suggestions
// ignore: must_be_immutable
class AppTextField extends TextField {
const AppTextField({
bool _initialized = false;
AppTextField({
// default settings to turn off autocorrect
super.autocorrect = false,
super.enableSuggestions = false,
@ -85,5 +89,22 @@ class AppTextField extends TextField {
super.canRequestFocus,
super.spellCheckConfiguration,
super.magnifierConfiguration,
}) : super(decoration: decoration);
}) : super(decoration: decoration) {
// TODO: Replace this with a custom lint check, if possible
Timer.run(() {
assert(_initialized, 'AppTextField not initialized!');
});
}
Widget init() {
_initialized = true;
return Builder(
builder: (context) => DefaultSelectionStyle(
selectionColor: decoration?.errorText != null
? Theme.of(context).colorScheme.error
: null,
child: this,
),
);
}
}

View File

@ -14,12 +14,17 @@
* limitations under the License.
*/
import 'dart:async';
import 'package:flutter/material.dart';
import 'app_input_decoration.dart';
/// TextFormField without autocorrect and suggestions
// ignore: must_be_immutable
class AppTextFormField extends TextFormField {
final AppInputDecoration? decoration;
bool _initialized = false;
AppTextFormField({
// default settings to turn off autocorrect
super.autocorrect = false,
@ -30,7 +35,7 @@ class AppTextFormField extends TextFormField {
super.controller,
super.initialValue,
super.focusNode,
AppInputDecoration? decoration,
this.decoration,
super.textCapitalization,
super.textInputAction,
super.style,
@ -89,5 +94,22 @@ class AppTextFormField extends TextFormField {
super.clipBehavior,
super.scribbleEnabled,
super.canRequestFocus,
}) : super(decoration: decoration);
}) : super(decoration: decoration) {
// TODO: Replace this with a custom lint check, if possible
Timer.run(() {
assert(_initialized, 'AppTextFormField not initialized!');
});
}
Widget init() {
_initialized = true;
return Builder(
builder: (context) => DefaultSelectionStyle(
selectionColor: decoration?.errorText != null
? Theme.of(context).colorScheme.error
: null,
child: this,
),
);
}
}