InputText constructor

InputText({
  1. Key? key,
  2. String value = "",
  3. bool obscureText = false,
  4. String placeholder = "",
  5. String validChars = '',
  6. InputType type = InputType.text,
  7. bool emptyOnSubmit = false,
  8. dynamic onChange(
    1. String,
    2. dynamic
    )?,
  9. dynamic onSubmit(
    1. String,
    2. dynamic
    )?,
  10. int maxLines = 1,
  11. Icon? prefixIcon,
  12. Icon? suffixIcon,
  13. Color? color,
  14. Color? placeholderColor,
  15. TextAlign textAlign = TextAlign.left,
  16. double? fontSize,
  17. String? label,
  18. bool showBorder = false,
  19. Color? borderColor,
})

Implementation

InputText({
  super.key,
  String value = "",
  this.obscureText = false,
  this.placeholder = "",
  this.validChars = '',
  this.type = InputType.text,
  this.emptyOnSubmit = false,
  this.onChange,
  this.onSubmit,
  this.maxLines = 1,
  this.prefixIcon,
  this.suffixIcon,
  this.color,
  this.placeholderColor,
  this.textAlign = TextAlign.left,
  this.fontSize,
  this.label,
  this.showBorder = false,
  this.borderColor,
}) {
  text.value = value;
  controller = TextEditingController(text: text.value);
  controller.addListener(() {
    text.value = controller.text;
    if (onChange != null) {
      onChange!(text.value, this);
    }
  });

  if (type == InputType.email) {
    validChars = 'a-zA-Z0-9@._-';
    keyboardType = TextInputType.emailAddress;
  } else if (type == InputType.password) {
    validChars = '';
    obscureText = true;
  } else if (type == InputType.number) {
    validChars = '0-9';
    keyboardType = TextInputType.number;
  } else if (type == InputType.phone) {
    validChars = '0-9+';
    keyboardType = TextInputType.phone;
  } else if (type == InputType.url) {
    validChars = 'a-zA-Z0-9@._-:/';
    keyboardType = TextInputType.url;
  } else {
    keyboardType = TextInputType.text;
  }

  showPassword.value = !obscureText;

  if (validChars.isEmpty) {
    validChars = '.*';
  } else {
    validChars = '[$validChars]';
  }
}