'Flutter: obscureText, how to stop showing typed characters
When typing text into a field with obscureText: true, each typed character is displayed briefly before being converted to a bullet. How do you stop the behavior?
Solution 1:[1]
This was fixed on Web/Desktop, but there's no option to do it on Mobile. You can create a custom TextEditingController as suggested in this comment:
class ObscuringTextEditingController extends TextEditingController {
@override
TextSpan buildTextSpan({TextStyle style, bool withComposing}) {
var displayValue = '•' * value.text.length;
if (!value.composing.isValid || !withComposing) {
return TextSpan(style: style, text: displayValue);
}
final TextStyle composingStyle = style.merge(
const TextStyle(decoration: TextDecoration.underline),
);
return TextSpan(
style: style,
children: <TextSpan>[
TextSpan(text: value.composing.textBefore(displayValue)),
TextSpan(
style: composingStyle,
text: value.composing.textInside(displayValue),
),
TextSpan(text: value.composing.textAfter(displayValue)),
],
);
}
}
Remove obscureText and use controller:
var passwordController = ObscuringTextEditingController();
TextField(
controller: passwordController,
decoration: const InputDecoration(hintText: 'Password'),
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sami Haddad |
