Skip to content

Instantly share code, notes, and snippets.

@shishirthedev
Created July 24, 2019 10:54
Show Gist options
  • Save shishirthedev/b79ef8b8ab29550fcbc5d93f8fb87687 to your computer and use it in GitHub Desktop.
Save shishirthedev/b79ef8b8ab29550fcbc5d93f8fb87687 to your computer and use it in GitHub Desktop.
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