Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i put 1 icon and 1 iconbutton in TextFormField Flutter

I want to put 1 icon and 1 iconbutton in a textformfield. I added but both settled on the left.

I want to put the iconbutton on the left.

TextFormField(
      keyboardType: TextInputType.visiblePassword,
      obscureText: !_showPassword,
      decoration: InputDecoration(
        labelStyle: TextStyle(color: Colors.black87),
        labelText: 'Enter password',
        prefixIcon: Row(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Icon(Icons.lock),
            IconButton(
                icon: _showPassword ? Icon(Icons.lock_open) : Icon(Icons.lock),
                onPressed: () {
                  setState(() {
                    _showPassword = !_showPassword;
                  });
                }),
          ],
        ),
        border: OutlineInputBorder(),
      ),
    );

Can someone help me?
Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Screenshot

>Solution :

Use suffix icon

TextField(
 prefixIcon: Icon(Icons.lock),
 suffixIcon: IconButton(
                icon: _showPassword ? Icon(Icons.lock_open) : Icon(Icons.lock),
                onPressed: () {
                  setState(() {
                    _showPassword = !_showPassword;
                  });
                }),
),

You can add icon to prefix and icon button to suffix

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading