XInput constructor
XInput({
- Key? key,
- dynamic row = true,
- dynamic label,
- dynamic readOnly,
- dynamic inputFormatters,
- dynamic labelWidget,
- dynamic labelAlign,
- dynamic labelWidth = 0.0,
- dynamic labelStyle,
- dynamic padding,
- dynamic radius,
- dynamic hintText,
- dynamic hintStyle,
- dynamic keyboardType,
- dynamic controller,
- dynamic obscureText,
- dynamic validator,
- dynamic textAlign,
- dynamic border,
- dynamic onChanged,
- dynamic contentPadding,
- dynamic required,
- dynamic enabled,
- dynamic style,
- dynamic maxLines,
- dynamic autofocus,
- dynamic maxLength,
- dynamic focusNode,
- dynamic selectionControls,
- dynamic fillColor,
- dynamic hintMaxLines,
- dynamic expands,
- dynamic counterText,
- dynamic suffixIcon,
- dynamic prefixIcon,
- dynamic showClose,
- 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);
};
}