How to remove auto create space while choose suggestion on keyboard in flutter

Viewed 94

enter image description here

AppTextField(
                         maxLength: 40,
                         controller: emailC,
                         padding: const EdgeInsets.symmetric(
                             horizontal: 10, vertical: 2),
                         hintText: 'youremail@gmail.com',
                         onChanged: () {},
                         width: Get.width,
                         textColor: AppColors.primary,
                         elevation: 0,
                         textFieldColor: AppColors.textField,
                         height: 47,
                         textStyle: AppTextStyle.regularBlack14,
                       ),
2 Answers

I have previously ended up using a validator to process the user input, and removing the extra space there. If spaces are not allowed, you could also .strip() the value in the value changed callback.

Take a look at the simple validator example from the docs: text form field with validation.

And there, you could have something like this:

valideInput(value) {
  // strip trailing spaces
  value = value.strip();

  // actual validation like empty checks
  if (value == null || value.length == 0) return 'Please enter a value!';

  return null;
}
// Completetly successful 

setState(() {
      formatedEmail = emailC.text.replaceAll(' ', '');
});
Related