XInput constructor

XInput({
  1. Key? key,
  2. dynamic row = true,
  3. dynamic label,
  4. dynamic readOnly,
  5. dynamic inputFormatters,
  6. dynamic labelWidget,
  7. dynamic labelAlign,
  8. dynamic labelWidth = 0.0,
  9. dynamic labelStyle,
  10. dynamic padding,
  11. dynamic radius,
  12. dynamic hintText,
  13. dynamic hintStyle,
  14. dynamic keyboardType,
  15. dynamic controller,
  16. dynamic obscureText,
  17. dynamic validator,
  18. dynamic textAlign,
  19. dynamic border,
  20. dynamic onChanged,
  21. dynamic contentPadding,
  22. dynamic required,
  23. dynamic enabled,
  24. dynamic style,
  25. dynamic maxLines,
  26. dynamic autofocus,
  27. dynamic maxLength,
  28. dynamic focusNode,
  29. dynamic selectionControls,
  30. dynamic fillColor,
  31. dynamic hintMaxLines,
  32. dynamic expands,
  33. dynamic counterText,
  34. dynamic suffixIcon,
  35. dynamic prefixIcon,
  36. dynamic showClose,
  37. dynamic eyeChange,
})

Implementation

XInput(
    {Key? key,
    row = true,
    label,
    readOnly,
    inputFormatters,
    labelWidget,
    labelAlign,
    labelWidth = 0.0,
    labelStyle,
    padding,
    radius,
    hintText,
    hintStyle,
    keyboardType,
    controller,
    obscureText,
    validator,
    textAlign,
    border,
    onChanged,
    contentPadding,
    required,
    enabled,
    style,
    maxLines,
    autofocus,
    maxLength,
    focusNode,
    selectionControls,
    fillColor,
    hintMaxLines,
    expands,
    counterText,
    suffixIcon,
    prefixIcon,
    showClose,
    eyeChange}) {
  _inputFormatters = inputFormatters;
  _prefixIcon = prefixIcon;
  _counterText = counterText;
  _readOnly = readOnly;
  _row = row ?? false;
  _focusNode = focusNode;
  _label = label;
  _labelWidget = labelWidget;
  _labelAlign = labelAlign ?? Alignment.centerLeft;
  _labelWidth = _row! ? (labelWidth ?? 0.w) : null;
  _labelStyle = labelStyle;
  _hintText = hintText;
  _hintStyle = hintStyle;
  _keyboardType = keyboardType;
  _controller = controller;

  _textAlign = textAlign;
  _border = border;
  _contentPadding =
      contentPadding ?? EdgeInsets.only(top: 10.w, bottom: 10.w);
  _enabled = enabled;
  _radius = radius ?? 10.w;
  _obscureText = obscureText;
  _style = style;
  _maxLines = obscureText ?? false ? 1 : maxLines;
  _fillColor = fillColor;
  _autofocus = autofocus ?? false;

  _selectionControls = selectionControls;
  _hintMaxLines = hintMaxLines;
  _expands = expands ?? false;

  ///密码眼睛
  if (eyeChange != null) {
    _suffixIcon = GestureDetector(
      onLongPressStart: (details) {
        eyeChange?.call(false);
      },
      onLongPressDown: (v) {
        eyeChange?.call(false);
      },
      onTap: () {
        eyeChange?.call(true);
      },
      onLongPressUp: () {
        eyeChange?.call(true);
      },
      onLongPressEnd: (details) {
        eyeChange?.call(true);
      },
      child: _obscureText ?? false
          ? const Icon(
              Icons.visibility_off_outlined,
              size: 22,
            )
          : const Icon(Icons.visibility_outlined, size: 22),
    );
    //输入框清空
  } else if (showClose ?? false) {
    _suffixIcon = controller.text.length > 0
        ? GestureDetector(
            onTap: () {
              controller.text = '';
              onChanged?.call('');
            },
            child: Icon(
              Icons.close_outlined,
              size: 38.w,
            ),
          )
        : null;
  } else {
    _suffixIcon = suffixIcon;
  }

  _onChanged = (v) {
    if (maxLength != null && v.length > maxLength) {
      controller.text = controller.text.substring(0, maxLength);
      controller.selection =
          TextSelection.fromPosition(TextPosition(offset: maxLength ?? 0));
    }
    onChanged?.call(v);
  };
}