Created
July 24, 2019 10:54
-
-
Save shishirthedev/b79ef8b8ab29550fcbc5d93f8fb87687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Initiate passwordVisible to false in initState() | |
@override | |
void initState() { | |
passwordVisible = false; | |
} | |
Following is the TextFormField widget : | |
TextFormField( | |
keyboardType: TextInputType.text, | |
controller: _userPasswordController, | |
obscureText: passwordVisible,//This will obscure text dynamically | |
decoration: InputDecoration( | |
labelText: 'Password', | |
hintText: 'Enter your password', | |
// Here is key idea | |
suffixIcon: IconButton( | |
icon: Icon( | |
// Based on passwordVisible state choose the icon | |
passwordVisible | |
? Icons.visibility | |
: Icons.visibility_off, | |
color: Theme.of(context).primaryColorDark, | |
), | |
onPressed: () { | |
// Update the state i.e. toogle the state of passwordVisible variable | |
setState(() { | |
passwordVisible = !passwordVisible; | |
}); | |
}, | |
), | |
), | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment