EditText function
TextFormField
EditText({
- Key? key,
- TextEditingController? controller,
- ValueListener<
String> ? valueListener, - String? initialValue,
- String? label,
- String? hint,
- int? minLength,
- int maxLength = 256,
- bool allowEmpty = true,
- OnValue<
String> ? onSubmitted, - Widget? prefixIcon,
- String? helperText,
- String? errorText,
- bool clear = false,
- Widget? suffixIcon,
- Color? cursorColor,
- TextValidator? validator,
- List<
TextInputFormatter> ? inputFormatters, - TextInputType? keyboardType = TextInputType.text,
- TextInputAction? textInputAction = TextInputAction.next,
- FocusNode? focusNode,
- TextAlign textAlign = TextAlign.start,
- bool autofocus = false,
- int? maxLines,
- int? minLines,
- bool readonly = false,
- InputDecoration? decoration,
- void onChanged()?,
- void onTapOutside()?,
Implementation
TextFormField EditText({
Key? key,
TextEditingController? controller,
ValueListener<String>? valueListener,
String? initialValue,
String? label,
String? hint,
int? minLength,
int maxLength = 256,
bool allowEmpty = true,
OnValue<String>? onSubmitted,
Widget? prefixIcon,
String? helperText,
String? errorText,
bool clear = false,
Widget? suffixIcon,
Color? cursorColor,
TextValidator? validator,
List<TextInputFormatter>? inputFormatters,
TextInputType? keyboardType = TextInputType.text,
TextInputAction? textInputAction = TextInputAction.next,
FocusNode? focusNode,
TextAlign textAlign = TextAlign.start,
bool autofocus = false,
int? maxLines,
int? minLines,
bool readonly = false,
InputDecoration? decoration,
void Function(String)? onChanged,
void Function(PointerDownEvent)? onTapOutside,
}) {
TextEditingController c = controller ?? TextEditingController(text: initialValue ?? valueListener?.value);
FocusNode node = focusNode ?? FocusNode();
var lv = LengthValidator(minLength: minLength ?? 0, maxLength: maxLength, allowEmpty: allowEmpty);
TextValidator tv = validator == null ? lv : ListValidator([validator, lv]);
return TextFormField(
key: key ?? UniqueKey(),
controller: c,
maxLength: maxLength,
validator: tv,
maxLines: maxLines,
minLines: minLines,
onFieldSubmitted: onSubmitted ?? valueListener?.onChanged,
onChanged: onChanged ?? valueListener?.onChanged,
textAlign: textAlign,
keyboardType: keyboardType,
textInputAction: textInputAction,
inputFormatters: inputFormatters,
readOnly: readonly,
autofocus: autofocus,
cursorColor: cursorColor,
focusNode: node,
onTapOutside: onTapOutside ?? (e) => node.unfocus(),
decoration:
decoration ??
InputDecoration(
labelText: label,
hintText: hint,
counterText: "",
prefixIcon: prefixIcon,
helperText: helperText,
errorText: errorText,
suffixIcon: suffixIcon ?? (!clear ? null : IconButton(icon: const Icon(Icons.clear), onPressed: () => c.clear())),
),
);
}