toggel bhave in flutter on same class
bool isHidden=true
passwordTF() {
return TextFormField(
maxLength: 20,
obscureText: isHidden,
decoration: InputDecoration(
enabled: true,
labelText: "Password",
labelStyle: TextStyle(fontSize: 20, color: Colors.white),
icon: Icon(Icons.lock_open_outlined, size: 30, color: Colors.white,),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blue, width: 2.0,style: BorderStyle.solid,
),
),
fillColor: Colors.white.withOpacity(0.6),
filled: true,
focusColor: Colors.white,
suffixIcon: InkWell(
onTap:_showPassword,
child: Icon(isHidden ? Icons.visibility_off : Icons.visibility, color: Colors.white,)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white, width: 2.0,style: BorderStyle.solid),
),
hintText: "@123",
hintStyle: TextStyle(color: Colors.grey, fontSize: 10),
),
validator: PasswordValidation, //if you want display validation
);
}
void _showPassword() {
setState(() {
isHidden = !isHidden;
});
}