textFormField method
Widget
textFormField({
- required TextEditingController controller,
- required String labelText,
- void onChanged()?,
- String? validator()?,
- TextInputType? keyboardType,
- double? maxWidth,
- int? maxLines,
- bool? obscureText,
- void onPressedSuffixIcon()?,
- IconData? suffixIcon,
customized text form field with default option
Implementation
Widget textFormField({
required TextEditingController controller,
required String labelText,
void Function(String)? onChanged,
String? Function(String?)? validator,
TextInputType? keyboardType,
double? maxWidth,
int? maxLines,
bool? obscureText,
void Function()? onPressedSuffixIcon,
IconData? suffixIcon,
}) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 8,
offset: const Offset(0, 3),
),
],
),
constraints: BoxConstraints(
maxWidth: maxWidth ?? 370,
),
child: TextFormField(
maxLines: maxLines ?? 1,
controller: controller,
obscureText: obscureText ?? false,
onChanged: onChanged,
decoration: InputDecoration(
labelText: labelText,
labelStyle: const TextStyle(color: Colors.grey),
alignLabelWithHint: true,
suffixIcon: onPressedSuffixIcon != null
? IconButton(
onPressed: onPressedSuffixIcon,
icon: obscureText != null
? Icon(
obscureText
? Icons.remove_red_eye
: CupertinoIcons.eye_slash_fill,
color: themeColor,
)
: Icon(
suffixIcon ?? Icons.remove_red_eye,
color: themeColor,
),
)
: suffixIcon != null
? Icon(
suffixIcon,
color: themeColor,
)
: null,
hintStyle: const TextStyle(
color: Colors.grey,
),
errorStyle: const TextStyle(
fontSize: 0,
),
hintText: labelText,
contentPadding:
const EdgeInsets.symmetric(horizontal: 14, vertical: 16),
filled: true,
fillColor: primaryColor,
floatingLabelBehavior: FloatingLabelBehavior.never,
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.grey, width: 1.0),
borderRadius: BorderRadius.circular(10),
gapPadding: 0,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide:
BorderSide(color: Colors.grey.withOpacity(0.5), width: 1.0),
gapPadding: 0,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: const BorderSide(color: Colors.transparent, width: 1.0),
),
),
validator: validator,
keyboardType: keyboardType,
style: const TextStyle(
fontFamily: "Poppins",
),
),
);
}