Home > Software design >  How to remove auto create space while choose suggestion on keyboard in flutter
How to remove auto create space while choose suggestion on keyboard in flutter

Time:05-26

enter image description hereenter image description here AppTextField( maxLength: 40, controller: emailC, padding: const EdgeInsets.symmetric( horizontal: 10, vertical: 2), hintText: '[email protected]', onChanged: () {}, width: Get.width, textColor: AppColors.primary, elevation: 0, textFieldColor: AppColors.textField, height: 47, textStyle: AppTextStyle.regularBlack14, ),

CodePudding user response:

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;
}

CodePudding user response:

//// Completetly successful

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

  • Related