editText method
TextFormField
editText({
- Key? key,
- required String name,
- String? initialValue,
- String? label,
- String? hint,
- int? minLength,
- int maxLength = 256,
- bool allowEmpty = true,
- ValueChanged<
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,
- TextAlign textAlign = TextAlign.start,
- bool autofocus = false,
- int? maxLines,
- int? minLines,
- bool readonly = false,
- InputDecoration? decoration,
- InputBorder? border,
- void onChanged()?,
- void onTapOutside()?,
Implementation
TextFormField editText({
Key? key,
required String name,
String? initialValue,
String? label,
String? hint,
int? minLength,
int maxLength = 256,
bool allowEmpty = true,
ValueChanged<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,
TextAlign textAlign = TextAlign.start,
bool autofocus = false,
int? maxLines,
int? minLines,
bool readonly = false,
InputDecoration? decoration,
InputBorder? border,
void Function(String)? onChanged,
void Function(PointerDownEvent)? onTapOutside,
}) {
_nameControllerMap[name] ??= TextEditingController(text: initialValue);
_focusMap[name] ??= 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: _nameControllerMap[name],
maxLength: maxLength,
validator: tv,
maxLines: maxLines,
minLines: minLines,
onFieldSubmitted: onSubmitted,
onChanged: onChanged,
textAlign: textAlign,
keyboardType: keyboardType,
textInputAction: textInputAction,
inputFormatters: inputFormatters,
readOnly: readonly,
autofocus: autofocus,
cursorColor: cursorColor,
focusNode: _focusMap[name],
onTapOutside: onTapOutside ?? (e) => _focusMap[name]?.unfocus(),
decoration:
decoration ??
InputDecoration(
labelText: label,
hintText: hint,
counterText: "",
prefixIcon: prefixIcon,
helperText: helperText,
errorText: errorText,
border: border,
suffixIcon: suffixIcon ?? (!clear ? null : IconButton(icon: const Icon(Icons.clear), onPressed: () => _nameControllerMap[name]?.clear())),
),
);
}