inputFieldWidget static method
Widget
inputFieldWidget(
- BuildContext context,
- String keyName,
- String hintText,
- Function onValidate,
- Function onSaved, {
- String initialValue = "",
- dynamic 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,
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,
),
),
);
}