Home > front end >  Changing lowercase into upper case in real time in Flutter web
Changing lowercase into upper case in real time in Flutter web

Time:10-28

Basically, I am trying to get it so that when the user types in a lowercase letter, let's say "a", the screen will output an uppercase "A" instead. This is in flutter web using a keyboard. Any ideas?

CodePudding user response:

Widget TextFormField have a propriety textCapitalization

Show you :

TextFormField(
  keyboardType: TextInputType.text,
  textCapitalization: TextCapitalization.sentences,
),

You have different proprieties like

textCapitalization: TextCapitalization.characters,
textCapitalization: TextCapitalization.none, // Default
textCapitalization: TextCapitalization.sentences,
textCapitalization: TextCapitalization.words,

CodePudding user response:

You can use TextInputFormatter

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

And use like

TextField(
  inputFormatters: [ UpperCaseFormatter() ],
),
  • Related