How to add a Password input type in flutter makes the password user input is not visible , just like Android Native EditText 's inputtype:password?
In case you are using the TextField
widget (or something that derives from this widget), you can use the obscureText
property and set it to true
.
More details can be found here: https://docs.flutter.io/flutter/material/TextField/obscureText.html
Additionally, consider adding these properties to prevent input suggestions because they risk revealing at least part of the password input to screen viewers.
enableSuggestions: false,
autocorrect: false,
Just add obscureText: true
in TextFormField
:
TextFormField(
obscureText: true,
decoration: const InputDecoration(
labelText: 'Password',
),
validator: (String value) {
if (value.trim().isEmpty) {
return 'Password is required';
}
},
),
There are only two places where we can hide the password.
1. Using TextFormField
TextFormField(
obscureText: true,
decoration: const InputDecoration(
labelText: 'Password',
),
),
2. Using TextField
TextField(
obscureText: true,
decoration: const InputDecoration(
labelText: 'Password',
),
)