<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nikesh Maharjan</title>
    <description>The latest articles on DEV Community by Nikesh Maharjan (@nikesh_maharjan_14e006fec).</description>
    <link>https://dev.to/nikesh_maharjan_14e006fec</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3328502%2Ff26ad1f2-ac40-4814-a33f-57e876077b4b.png</url>
      <title>DEV Community: Nikesh Maharjan</title>
      <link>https://dev.to/nikesh_maharjan_14e006fec</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nikesh_maharjan_14e006fec"/>
    <language>en</language>
    <item>
      <title>Show/Hide Password In Flutter</title>
      <dc:creator>Nikesh Maharjan</dc:creator>
      <pubDate>Sun, 06 Jul 2025 15:58:15 +0000</pubDate>
      <link>https://dev.to/nikesh_maharjan_14e006fec/showhide-password-in-flutter-476i</link>
      <guid>https://dev.to/nikesh_maharjan_14e006fec/showhide-password-in-flutter-476i</guid>
      <description>&lt;p&gt;I was working on a login screen the other day, and as usual, I wanted to add that little eye icon to let users show or hide their password. You see it in almost every app these days, and it does help users avoid typos when typing a password on mobile.&lt;br&gt;
In Flutter, it turns out this is pretty straightforward. What I usually do is keep a boolean in my state, something like &lt;strong&gt;_obscureText&lt;/strong&gt; = true; to track whether the password should be hidden. Then, in the TextFormField, I set &lt;strong&gt;obscureText: _obscureText&lt;/strong&gt;. That part is standard.&lt;br&gt;
The interesting part is adding the toggle. Flutter makes it simple because you can add a &lt;strong&gt;suffixIcon&lt;/strong&gt; to your input field. I just drop an IconButton there, and its icon changes depending on &lt;strong&gt;_obscureText&lt;/strong&gt;. So, when the user taps it, I call &lt;strong&gt;setState&lt;/strong&gt; to flip the boolean, and Flutter updates the UI automatically.&lt;br&gt;
Here's basically what the code looks like, without overcomplicating it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TextFormField(
 obscureText: _obscureText,
 decoration: InputDecoration(
 labelText: 'Password',
 suffixIcon: IconButton(
 icon: Icon(
 _obscureText ? Icons.visibility : Icons.visibility_off,
 ),
 onPressed: () {
 setState(() {
 _obscureText = !_obscureText;
      });
    },
   ),
 ),
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's really it. Nothing fancy, but it works well. I've used this in multiple apps, and users find it handy. It feels like one of those small details that make your app look more professional and easier to use.&lt;br&gt;
I thought I'd write this down because I remember the first time I had to do it, I assumed it would be more complicated. But it turned out to be just a few lines of code and a simple toggle.&lt;br&gt;
Full Source Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class PasswordField extends StatefulWidget {
 @override
 _PasswordFieldState createState() =&amp;gt; _PasswordFieldState();
}
class _PasswordFieldState extends State&amp;lt;PasswordField&amp;gt; {
 bool _obscureText = true;
@override
 Widget build(BuildContext context) {
 return TextFormField(
 obscureText: _obscureText,
 decoration: InputDecoration(
 labelText: 'Password',
 suffixIcon: IconButton(
 icon: Icon(
 _obscureText ? Icons.visibility : Icons.visibility_off,
 ),
 onPressed: () {
 setState(() {
 _obscureText = !_obscureText;
        });
      },
     ),
    ),
   );
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're building your own login or signup form, give it a try. It's one of those small features that users appreciate more than we think.&lt;/p&gt;

</description>
      <category>flutter</category>
    </item>
  </channel>
</rss>
