textField static method
Widget
textField(
- BuildContext context,
- TextEditingController controller,
- String hint, {
- Color? fontColor,
- Color? hintColor,
- double? fontSize,
- double? hintFontSize,
- TextInputType? inputType,
- int maxLength = 100,
- TextAlign? textAlign,
- FocusNode? focusNode,
- bool? obscureText,
- bool? disabled,
- List<
TextInputFormatter> ? inputFormatters, - Key? key,
- int? maxLines,
- String? errorText,
- Color? errorColor,
- double? errorFontSize,
- double? borderWidth,
- Color? borderColor,
- double? radius,
- EdgeInsets? padding,
- bool bold = false,
- EdgeInsets? margin,
- ValueChanged<
String> ? onSubmit, - TextInputAction? inputAction,
- Color? bgColor,
- Widget? prefix,
- Widget? suffix,
- bool autofocus = false,
快捷创建输入框
Implementation
static Widget textField(BuildContext context, TextEditingController controller,
String hint, { Color? fontColor, Color? hintColor, double? fontSize,double? hintFontSize, TextInputType? inputType,
int maxLength = 100, TextAlign? textAlign, FocusNode? focusNode, bool? obscureText,
bool? disabled, List<TextInputFormatter>? inputFormatters, Key? key,
int? maxLines, String? errorText, Color? errorColor, double? errorFontSize,
double? borderWidth, Color? borderColor, double? radius, EdgeInsets? padding,
bool bold = false, EdgeInsets? margin, ValueChanged<String>? onSubmit,
TextInputAction? inputAction, Color? bgColor, Widget? prefix, Widget? suffix,
bool autofocus = false
}){
return Padding(padding: margin??EdgeInsets.zero, child: TextField(key: key, controller: controller,
maxLines: obscureText==true ? 1: maxLines,
maxLength: maxLength,
keyboardType: (maxLines==null&&obscureText!=true) ? TextInputType.multiline : (inputType ?? TextInputType.text),
enabled: !(disabled ?? false),
autofocus: autofocus,
textInputAction: inputAction ?? TextInputAction.done,
textAlignVertical: TextAlignVertical.center,
textAlign: textAlign??TextAlign.left,
focusNode: focusNode,
obscureText: obscureText??false,
onSubmitted: (v)=> onSubmit?.call(v),
decoration: InputDecoration(
prefixIcon: prefix,
suffixIcon: suffix,
isCollapsed: true,
counterText: "",
filled: bgColor!=null,
fillColor: bgColor,
focusedBorder: (borderWidth!=null || borderColor!=null|| radius!=null) ?
OutlineInputBorder(borderSide: BorderSide(width: borderWidth??1, color: Theme.of(context).primaryColor),
borderRadius: BorderRadius.circular(radius??0)) : InputBorder.none,
hintText: hint,
errorText: errorText!=null && errorText.isNotEmpty ? errorText : null,
errorStyle: TextStyle(color: errorColor, fontSize: errorFontSize),
contentPadding: padding ?? EdgeInsets.zero,
disabledBorder: (borderWidth!=null || borderColor!=null|| radius!=null) ?
OutlineInputBorder(borderSide: BorderSide(width: borderWidth??1,
color: borderColor ?? Theme.of(context).dividerColor),
borderRadius: BorderRadius.circular(radius??0)) : InputBorder.none,
enabledBorder: (borderWidth!=null || borderColor!=null|| radius!=null) ?
OutlineInputBorder(borderSide: BorderSide(width: borderWidth??1,
color: borderColor ?? Theme.of(context).dividerColor) ,
borderRadius: BorderRadius.circular(radius??0), gapPadding: 0) : InputBorder.none,
hintStyle: TextStyle(
color: hintColor ?? Theme.of(context).colorScheme.tertiary, fontSize: hintFontSize??(fontSize??16),
fontWeight: bold ? FontWeight.bold : FontWeight.normal
)),
style: TextStyle(color: fontColor ?? Theme.of(context).colorScheme.primary, fontSize: fontSize??16,
fontWeight: bold ? FontWeight.bold : FontWeight.normal),
),);
}