By default, Flutter adds a visibility toggle icon when obscureText is set to true in a TextField. However, when you need to use a custom icon (e.g., with suffixIcon), you can simply provide your own widget in the suffixIcon parameter of the InputDecoration, and the default visibility icon will be replaced.
Here's how you can achieve this by using the TextField widget, setting obscureText, and adding a custom suffixIcon to handle toggling between visibility states:
If you want the suffixIcon to be optional (e.g., only show it for passwords but not for other input fields), you can add conditional logic inside the suffixIcon field to show or hide it based on the type of input.