textField static method

Widget textField(
  1. BuildContext context,
  2. TextEditingController controller,
  3. String hint, {
  4. Color? fontColor,
  5. Color? hintColor,
  6. double? fontSize,
  7. double? hintFontSize,
  8. TextInputType? inputType,
  9. int maxLength = 100,
  10. TextAlign? textAlign,
  11. FocusNode? focusNode,
  12. bool? obscureText,
  13. bool? disabled,
  14. List<TextInputFormatter>? inputFormatters,
  15. Key? key,
  16. int? maxLines,
  17. String? errorText,
  18. Color? errorColor,
  19. double? errorFontSize,
  20. double? borderWidth,
  21. Color? borderColor,
  22. double? radius,
  23. EdgeInsets? padding,
  24. bool bold = false,
  25. EdgeInsets? margin,
  26. ValueChanged<String>? onSubmit,
  27. TextInputAction? inputAction,
  28. Color? bgColor,
  29. Widget? prefix,
  30. Widget? suffix,
  31. 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),
  ),);
}