build method
Implementation
@override
Widget build(BuildContext context) {
bool pwd = password ?? false;
List<TextInputFormatter> formats = [
...?inputFormaters,
if (allowExp != null) InputFormats.allow(allowExp!),
if (denyExp != null) InputFormats.deny(denyExp!),
if (maxLength != null) InputFormats.maxLength(maxLength!),
if (maxLines == 1) InputFormats.singleLine,
];
Widget? makeSuffixIcon() {
if (noClear && !pwd) return null;
Icon? icon;
if (pwd) {
icon = _showPassword ? const Icon(Icons.visibility_off, size: 16) : const Icon(Icons.visibility, size: 16);
} else {
icon = Icons.clear_rounded.icon(size: 16);
}
return IconButton(
onPressed: () {
if (pwd) {
_showPassword = !_showPassword;
} else {
controller.clear();
onClear?.call();
onChanged?.call("");
}
updateState();
},
icon: icon);
}
return TextFormField(
key: UniqueKey(),
focusNode: focusNode,
controller: controller,
textAlign: textAlign ?? TextAlign.start,
style: themeData.textTheme.titleMedium,
obscureText: pwd && !_showPassword,
maxLength: maxLength,
maxLines: maxLines,
minLines: minLines,
autofocus: autofucus,
readOnly: readOnly,
inputFormatters: formats,
keyboardType: keyboardType,
validator: validator,
decoration: InputDecoration(
labelText: label,
hintText: hint,
helperText: helpText,
prefixIcon: icon,
counterText: counterText,
errorText: errorText,
border: border,
suffixIcon: makeSuffixIcon(),
),
onChanged: onChanged,
onFieldSubmitted: onSubmit,
);
}