In my Flutter app, I use a TextFormField
, so my users can enter a password.
In order to hide the characters while they are being typed, I set the obscureText
property to true
. But on some devices, when I type a character, that character is visible for a second or so.
Even though I know it’s a very common behavior, is it possible to completely hide the character while it is being typed, and show only the obscuring character instead, aside from using a special font only made of dots?
Thanks for your help.
2
Answers
You can extend
TextEditingController
and override itsbuildTextSpan
to create your own obscuringTextField
:Please note that this is only a minimal implementation for sample purpose. You might need to be aware of other aspects from the original
buildTextSpan
method that may need to be implemented as well in the overriding method.This answer is a modified version of my answer on another question (with a different goal): https://stackoverflow.com/a/77791236/13625293
Looks like this is depending on which system you run your Flutter application. If you run it in the web for example, you will see that it hides all characters:
https://api.flutter.dev/flutter/material/TextField-class.html
On Android it checks the system settings to show the last character.
Look in your Android settings for "Make password visible" and disable it.