how to add image in flutter TextFormField inside prefixIcon

3,604

You can add the prefixIcon as follow in the TextFormField Widget,

prefixIcon: Padding(
                padding: const EdgeInsets.all(10.0),
                child: Image.asset(
                  'assets/facebook_logo.jpg',
                  width: 20,
                  height: 20,
                  fit: BoxFit.fill,
                ),
              ),

prefixIcon is a 48*48 px wide widget by default as per flutter documentation. so to decrease the size of the icon add the padding on all the size and you will be able to adjust as per your requirements.

Share:
3,604
Husamuldeen
Author by

Husamuldeen

Updated on December 16, 2022

Comments

  • Husamuldeen
    Husamuldeen over 1 year

    in the TextFormField the prefixIcon take a widget, I used the Image.asset(lock,width: 10,height: 10,), but it had big size bigger than 20, what I do?

    • Dinesh Nagarajan
      Dinesh Nagarajan over 4 years
      Add some of your code you tried with TextFormField
  • Alex.F
    Alex.F almost 3 years
    Check out How to Answer to improve this answer.