editText method

TextFormField editText({
  1. Key? key,
  2. required String name,
  3. String? initialValue,
  4. String? label,
  5. String? hint,
  6. int? minLength,
  7. int maxLength = 256,
  8. bool allowEmpty = true,
  9. ValueChanged<String>? onSubmitted,
  10. Widget? prefixIcon,
  11. String? helperText,
  12. String? errorText,
  13. bool clear = false,
  14. Widget? suffixIcon,
  15. Color? cursorColor,
  16. TextValidator? validator,
  17. List<TextInputFormatter>? inputFormatters,
  18. TextInputType? keyboardType = TextInputType.text,
  19. TextInputAction? textInputAction = TextInputAction.next,
  20. TextAlign textAlign = TextAlign.start,
  21. bool autofocus = false,
  22. int? maxLines,
  23. int? minLines,
  24. bool readonly = false,
  25. InputDecoration? decoration,
  26. InputBorder? border,
  27. void onChanged(
    1. String
    )?,
  28. void onTapOutside(
    1. PointerDownEvent
    )?,
})

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())),
        ),
  );
}