| 1 | import 'package:flutter/material.dart'; |
| 2 | |
| 3 | class InputField extends StatelessWidget { |
| 4 | final String hintText; |
| 5 | final TextInputType keyboardType; |
| 6 | final TextEditingController? controller; |
| 7 | final String? Function |
| 8 | final Widget? prefixIcon; |
| 9 | final bool? obscureText; |
| 10 | final Widget? suffixIcon; |
| 11 | final TextStyle? hintStyle; |
| 12 | final int? maxLines; |
| 13 | final int? minLines; |
| 14 | final bool? readOnly; |
| 15 | final InputBorder? border; |
| 16 | final Function(String |
| 17 | final Color? fillColor; |
| 18 | final Color? prefixIconColor; |
| 19 | final InputBorder? enabledBorder; |
| 20 | final bool? enabled; |
| 21 | final int? hintMaxLines; |
| 22 | final bool? autoFocus; |
| 23 | final bool? hideKeyboardOnClickOutside; |
| 24 | final List<String |
| 25 | const InputField({ |
| 26 | required this.hintText, |
| 27 | required this.keyboardType, |
| 28 | this.controller, |
| 29 | this.validator, |
| 30 | this.prefixIcon, |
| 31 | this.obscureText, |
| 32 | this.suffixIcon, |
| 33 | this.hintStyle, |
| 34 | this.maxLines, |
| 35 | this.minLines, |
| 36 | this.onChanged, |
| 37 | this.readOnly, |
| 38 | this.border, |
| 39 | this.fillColor, |
| 40 | this.prefixIconColor, |
| 41 | this.enabledBorder, |
| 42 | this.enabled, |
| 43 | this.hintMaxLines, |
| 44 | this.autoFocus, |
| 45 | this.hideKeyboardOnClickOutside, |
| 46 | this.autofillHints, |
| 47 | super.key, |
| 48 | }); |
| 49 | |
| 50 | @override |
| 51 | Widget build(BuildContext |
| 52 | return TextFormField( |
| 53 | autofocus: autoFocus ?? false, |
| 54 | readOnly: readOnly ?? false, |
| 55 | keyboardType: keyboardType, |
| 56 | controller: controller, |
| 57 | obscureText: obscureText ?? false, |
| 58 | minLines: minLines, |
| 59 | autofillHints: autofillHints, |
| 60 | maxLines: obscureText == null |
| 61 | ? maxLines |
| 62 | : obscureText == true |
| 63 | ? 1 |
| 64 | : maxLines, |
| 65 | decoration: InputDecoration( |
| 66 | hintText: hintText, |
| 67 | prefixIcon: prefixIcon, |
| 68 | hintMaxLines: hintMaxLines, |
| 69 | contentPadding: const EdgeInsets. |
| 70 | enabledBorder: enabledBorder, |
| 71 | enabled: enabled ?? true, |
| 72 | border: border ?? |
| 73 | OutlineInputBorder( |
| 74 | borderRadius: BorderRadius.circular( |
| 75 | borderSide: BorderSide.none, |
| 76 | ), |
| 77 | prefixIconColor: Colors.black, |
| 78 | fillColor: fillColor, |
| 79 | filled: true, |
| 80 | hintStyle: hintStyle ?? |
| 81 | TextStyle( |
| 82 | fontSize: Theme.of(context) |
| 83 | ), |
| 84 | suffixIcon: suffixIcon, |
| 85 | errorStyle: TextStyle( |
| 86 | color: Colors.red, |
| 87 | fontSize: Theme.of(context) |
| 88 | ), |
| 89 | ), |
| 90 | validator: validator, |
| 91 | onChanged: onChanged, |
| 92 | onTapOutside: (event) { |
| 93 | if (hideKeyboardOnClickOutside != null && hideKeyboardOnClickOutside == |
| 94 | FocusScope.of(context).unfocus |
| 95 | } |
| 96 | }, |
| 97 | ); |
| 98 | } |
| 99 | } |