EditText function

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

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