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?

PasswordsFlutter

Passwords Problem Overview


i meet a problem that Flutter 's TextInputType do not have a password type:

/// All possible enum values.
    
static const List<TextInputType> values = const <TextInputType>[
  text, multiline, number, phone, datetime, emailAddress, url,
];

how to make the password user input not visible? any one has a good idea ?

Passwords Solutions


Solution 1 - Passwords

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.

Additionally, consider adding these properties to prevent input suggestions because they risk revealing at least part of the password input to screen viewers.

obscureText: true,
enableSuggestions: false,
autocorrect: false,

Solution 2 - Passwords

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';
     }
   },
 ),

Solution 3 - Passwords

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',
                ),
              )

Solution 4 - Passwords

Using TextField

obscuringCharacter: "*",

 TextField(
        obscureText: true,
        onChanged: (){},
        obscuringCharacter: "*",
        decoration: InputDecoration(
            hintText: "Enter password",
            icon: Icon(Icons.lock,color: kPrimaryColor,),
        ),
      ),

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnaivorView Question on Stackoverflow
Solution 1 - PasswordsMaurits van BeusekomView Answer on Stackoverflow
Solution 2 - PasswordsZeeshan AnsariView Answer on Stackoverflow
Solution 3 - PasswordsJitesh MohiteView Answer on Stackoverflow
Solution 4 - PasswordsMuhammad Qamar IqbalView Answer on Stackoverflow