Last active
October 10, 2022 07:11
-
-
Save febritecno/1aed8d430fe0493bca98bcfb4f249b38 to your computer and use it in GitHub Desktop.
universal textField component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
class InputComponent extends StatelessWidget { | |
final Function(String)? onChanged; | |
final TextStyle? placeholderStyle, labelStyle; | |
final Color? color; | |
final Widget? suffix, prefix; | |
final String? label, initialValue, placeholder, labelText; | |
final FontWeight? fontWeight; | |
final Alignment? suffixAlign, prefixAlign; | |
final TextInputType? keyboardType; | |
final List<TextInputFormatter>? inputFormatters; | |
final double? labelSize, | |
fontSize, | |
suffixSize, | |
prefixSize, | |
paddingHorizontal, | |
paddingVertical; | |
final int? maxLines, minLines; | |
final TextInputAction? textInputAction; | |
final bool? enabled, readOnly, autofocus, obscureText; | |
final TextEditingController? controller; | |
final EdgeInsets? contentPadding; | |
final Widget? suffixIcon; | |
final Widget? prefixIcon; | |
const InputComponent( | |
{Key? key, | |
this.label, | |
this.suffix, | |
this.prefix, | |
this.fontWeight, | |
this.labelSize, | |
this.controller, | |
this.initialValue, | |
this.enabled, | |
this.suffixSize, | |
this.prefixSize, | |
this.suffixIcon, | |
this.contentPadding, | |
this.fontSize, | |
this.suffixAlign, | |
this.prefixAlign, | |
this.readOnly, | |
this.paddingHorizontal, | |
this.paddingVertical, | |
this.placeholder, | |
this.labelText, | |
this.keyboardType, | |
this.inputFormatters, | |
this.autofocus, | |
this.onChanged, | |
this.maxLines, | |
this.textInputAction, | |
this.minLines, | |
this.color, | |
this.prefixIcon, | |
this.placeholderStyle, | |
this.obscureText, | |
this.labelStyle}) | |
: super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
(label != null) | |
? Text(label ?? 'label', | |
style: textStyle.copyWith( | |
color: Colors.grey, | |
fontWeight: fontWeight ?? FontWeight.bold, | |
fontSize: labelSize ?? 14)) | |
: const SizedBox(), | |
TextFormField( | |
cursorColor: Colors.black, | |
minLines: minLines ?? 1, | |
maxLines: maxLines ?? 1, | |
obscureText: obscureText ?? false, | |
textInputAction: textInputAction ?? TextInputAction.done, | |
onChanged: onChanged, | |
autofocus: autofocus ?? false, | |
readOnly: readOnly ?? false, | |
controller: controller, | |
style: TextStyle( | |
color: color ?? Colors.black, | |
fontWeight: fontWeight ?? FontWeight.w400, | |
fontSize: fontSize ?? 20), | |
initialValue: initialValue, | |
decoration: InputDecoration( | |
hintText: placeholder, | |
hintStyle: placeholderStyle, | |
prefixIconConstraints: const BoxConstraints(), | |
enabled: enabled ?? true, | |
labelText: labelText, | |
labelStyle: labelStyle, | |
floatingLabelBehavior: FloatingLabelBehavior.never, | |
suffix: suffix ?? SizedBox(width: suffixSize ?? 0), | |
prefix: prefix ?? SizedBox(width: prefixSize ?? 0), | |
suffixIcon: suffixIcon, | |
prefixIcon: prefixIcon, | |
disabledBorder: UnderlineInputBorder( | |
borderSide: BorderSide(color: Colors.grey.shade300)), | |
fillColor: Colors.white, | |
enabledBorder: UnderlineInputBorder( | |
borderSide: BorderSide(color: Colors.grey.shade300)), | |
focusedBorder: UnderlineInputBorder( | |
borderSide: BorderSide(color: Colors.grey.shade400)), | |
contentPadding: contentPadding ?? | |
const EdgeInsets.symmetric(horizontal: 0, vertical: 12)), | |
keyboardType: keyboardType ?? TextInputType.text, | |
inputFormatters: inputFormatters ?? [], | |
), | |
], | |
); | |
} | |
} |
Author
febritecno
commented
Oct 10, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment