Home > Software design >  How to UpperCase all the letters of a textField?
How to UpperCase all the letters of a textField?

Time:11-19

I have a textField and I want to only accept UpperCase letters on it, so if I type 'asd' it have to be converted to 'ASD' in the field.

I already tried TextCapitalization.character but it keeps the caps lock activated and If I turn it off my next letters are showed in lower case. I don't want to accept lower case letters in any situation.

Is there a way to do it?

Edit - What I did

TextField(
      
        textCapitalization: TextCapitalization.characters,
    )

CodePudding user response:

You can use custom TextInputFormatter inside TextField( inputFormatters: [UppercaseInputFormatter()], ...)

class UppercaseInputFormatter extends TextInputFormatter {
  @override
  TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
    return newValue.copyWith(text: newValue.text.toUpperCase());
  }

}
  • Related