textField static method

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

快捷创建输入框

Implementation

static Widget textField(BuildContext context, TextEditingController controller,
    String hint, { Color? fontColor, Color? hintColor, double? fontSize,TextInputType? inputType,
      int maxLength = 100, TextAlign? textAlign, FocusNode? focusNode, bool? obscureText,
      bool? disabled, List<TextInputFormatter>? inputFormatters, Key? key,
      int? maxLines, double? borderWidth, Color? borderColor, double? radius, EdgeInsets? padding,
      bool bold = false, EdgeInsets? margin,  ValueChanged<String>? onSubmit,
      TextInputAction? inputAction, Color? bgColor,
      bool autofocus = false
    }){
  return Padding(padding: margin ?? EdgeInsets.zero, child: TextField(key: key, controller: controller,
    maxLines: obscureText==true ?  1:  maxLines,
    maxLength: maxLength,
    cursorColor: fontColor,
    inputFormatters: inputFormatters,
    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: null,
        suffixIcon: null,
        isCollapsed: true,
        counterText: "",
        filled: bgColor!=null,
        fillColor: bgColor,
        focusedBorder: (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,
        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,
        hintText: hint,
        hintStyle: TextStyle(
            color: hintColor ?? Theme.of(context).colorScheme.tertiary, fontSize: 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),
  ),);
}