PasswordInputTextFormField constructor
PasswordInputTextFormField({
- Key? key,
- TextEditingController? controller,
- String? initialValue,
- required int passwordLength,
- ValueChanged<
String> ? onSubmit, - PasswordDecoration decoration = const BoxLooseDecoration(),
- List<
TextInputFormatter> ? inputFormatter, - TextInputType keyboardType = TextInputType.text,
- FocusNode? focusNode,
- bool autoFocus = false,
- TextInputAction textInputAction = TextInputAction.done,
- bool enabled = true,
- FormFieldSetter<
String> ? onSaved, - FormFieldValidator<
String> ? validator, - AutovalidateMode autovalidate = AutovalidateMode.disabled,
- ValueChanged<
String> ? onChanged,
Implementation
PasswordInputTextFormField({
Key? key,
this.controller,
this.initialValue,
required this.passwordLength,
ValueChanged<String>? onSubmit,
PasswordDecoration decoration = const BoxLooseDecoration(),
List<TextInputFormatter>? inputFormatter,
TextInputType keyboardType = TextInputType.text,
FocusNode? focusNode,
bool autoFocus = false,
TextInputAction textInputAction = TextInputAction.done,
bool enabled = true,
FormFieldSetter<String>? onSaved,
FormFieldValidator<String>? validator,
AutovalidateMode autovalidate = AutovalidateMode.disabled,
ValueChanged<String>? onChanged,
}) : assert(initialValue == null || controller == null),
assert(passwordLength > 0),
super(
key: key,
initialValue:
controller != null ? controller.text : (initialValue ?? ''),
onSaved: onSaved,
validator: (value) {
var result = validator!(value);
if (result == null) {
if (value!.isEmpty) {
return 'Input field is empty.';
}
if (value.length < passwordLength) {
if (passwordLength - value.length > 1) {
return 'Missing ${passwordLength - value.length} digits of input.';
} else {
return 'Missing last digit of input.';
}
}
}
return result;
},
autovalidateMode: autovalidate,
enabled: enabled,
builder: (FormFieldState<String> field) {
final _PasswordInputTextFormFieldState state =
field as _PasswordInputTextFormFieldState;
return PasswordInputTextField(
passwordLength: passwordLength,
onSubmit: onSubmit,
decoration:
decoration.copyWith(errorText: field.errorText ?? ''),
inputFormatter: inputFormatter,
keyboardType: keyboardType,
controller: state._effectiveController,
focusNode: focusNode,
autoFocus: autoFocus,
textInputAction: textInputAction,
enabled: enabled,
onChanged: onChanged,
);
});