inputFieldWidget static method

Widget inputFieldWidget(
  1. BuildContext context,
  2. String keyName,
  3. String hintText,
  4. Function onValidate,
  5. Function onSaved, {
  6. String initialValue = "",
  7. dynamic obscureText = false,
  8. double fontSize = 18,
  9. double hintFontSize = 15,
  10. double paddingLeft = 20,
  11. double paddingRight = 20,
  12. double paddingTop = 0,
  13. double paddingBottom = 0,
  14. Icon? prefixIcon,
  15. Widget? suffixIcon,
  16. double borderRadius = 30,
  17. Color borderColor = Colors.redAccent,
  18. Color borderFocusColor = Colors.redAccent,
  19. double borderWidth = 2,
  20. double focusedBorderWidth = 2,
  21. double enabledBorderWidth = 1,
  22. bool showPrefixIcon = false,
  23. Color prefixIconColor = Colors.redAccent,
  24. double prefixIconPaddingLeft = 30,
  25. double prefixIconPaddingRight = 10,
  26. double prefixIconPaddingTop = 0,
  27. double prefixIconPaddingBottom = 0,
  28. bool isMultiline = false,
  29. Function? onChange,
  30. Color textColor = Colors.black,
  31. Color hintColor = Colors.black,
  32. Color validationColor = Colors.redAccent,
  33. double contentPadding = 6,
  34. int multilineRows = 4,
  35. bool isNumeric = false,
  36. Color backgroundColor = Colors.transparent,
  37. Color borderErrorColor = Colors.redAccent,
  38. Color borderFocusedErrorColor = Colors.redAccent,
  39. double errorBorderWidth = 2,
  40. double focusedErrorBorderWidth = 2,
  41. bool isReadonly = false,
  42. int maxLength = 50,
})

Implementation

static Widget inputFieldWidget(
  BuildContext context,
  String keyName,
  String hintText,
  Function onValidate,
  Function onSaved, {
  String initialValue = "",
  obscureText: false,
  double fontSize = 18,
  double hintFontSize = 15,
  double paddingLeft = 20,
  double paddingRight = 20,
  double paddingTop = 0,
  double paddingBottom = 0,
  Icon? prefixIcon,
  Widget? suffixIcon,
  double borderRadius = 30,
  Color borderColor = Colors.redAccent,
  Color borderFocusColor = Colors.redAccent,
  double borderWidth = 2,
  double focusedBorderWidth = 2,
  double enabledBorderWidth = 1,
  bool showPrefixIcon = false,
  Color prefixIconColor = Colors.redAccent,
  double prefixIconPaddingLeft = 30,
  double prefixIconPaddingRight = 10,
  double prefixIconPaddingTop = 0,
  double prefixIconPaddingBottom = 0,
  bool isMultiline = false,
  Function? onChange,
  Color textColor = Colors.black,
  Color hintColor = Colors.black,
  Color validationColor = Colors.redAccent,
  double contentPadding = 6,
  int multilineRows = 4,
  bool isNumeric = false,
  Color backgroundColor = Colors.transparent,
  Color borderErrorColor = Colors.redAccent,
  Color borderFocusedErrorColor = Colors.redAccent,
  double errorBorderWidth = 2,
  double focusedErrorBorderWidth = 2,
  bool isReadonly = false,
  int maxLength = 50,
}) {
  return Padding(
    padding: EdgeInsets.only(
      left: paddingLeft,
      right: paddingRight,
      top: paddingTop,
      bottom: paddingBottom,
    ),
    child: TextFormField(
      initialValue: initialValue,
      key: new Key(initialValue.toString()),
      obscureText: obscureText,
      readOnly: isReadonly,
      keyboardType: isNumeric ? TextInputType.number : null,
      maxLines: isMultiline ? multilineRows : 1,
      maxLength: maxLength,
      validator: (val) {
        return onValidate(val);
      },
      onSaved: (val) {
        return onSaved(val);
      },
      onChanged: (val) {
        return onChange != null ? onChange(val) : null;
      },
      style: TextStyle(
        fontSize: fontSize,
        color: textColor,
      ),
      decoration: InputDecoration(
        filled: true,
        fillColor: backgroundColor,
        contentPadding: EdgeInsets.all(contentPadding),
        counterText: "",
        errorStyle: TextStyle(
          color: validationColor,
        ),
        hintStyle: TextStyle(
          fontWeight: FontWeight.bold,
          fontSize: hintFontSize,
          color: hintColor,
        ),
        errorBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(borderRadius),
          borderSide: BorderSide(
            color: borderErrorColor,
            width: errorBorderWidth,
          ),
        ),
        focusedErrorBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(borderRadius),
          borderSide: BorderSide(
            color: borderFocusedErrorColor,
            width: focusedErrorBorderWidth,
          ),
        ),
        hintText: hintText,
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(borderRadius),
          borderSide: BorderSide(
            color: borderColor,
            width: enabledBorderWidth,
          ),
        ),
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(borderRadius),
          borderSide: BorderSide(
            color: borderColor,
            width: borderWidth,
          ),
        ),
        focusedBorder: OutlineInputBorder(
          borderSide: BorderSide(
            color: borderFocusColor,
            width: focusedBorderWidth,
          ),
          borderRadius: BorderRadius.circular(borderRadius),
        ),
        suffixIcon: suffixIcon,
        prefixIcon: showPrefixIcon
            ? Padding(
                child: IconTheme(
                  data: IconThemeData(color: prefixIconColor),
                  child: prefixIcon!,
                ),
                padding: EdgeInsets.only(
                  left: prefixIconPaddingLeft,
                  right: prefixIconPaddingRight,
                  top: prefixIconPaddingTop,
                  bottom: prefixIconPaddingBottom,
                ),
              )
            : null,
      ),
    ),
  );
}