Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add icon inside textfield

I have added icon to textfield using icon: Icon(Icons.mail), however it appears outside the textfield.

How can the position of icon be changed so that it is displayed inside the textfield.

TextField:

TextField(
  decoration: InputDecoration(
    icon: Icon(Icons.mail),
  ),
),
like image 561
cool_stuff_coming Avatar asked Feb 13 '19 20:02

cool_stuff_coming


2 Answers

You need to use prefixIcon attribute instead of icon like

TextField(
  decoration: InputDecoration(prefixIcon: Icon(Icons.mail)),
)
like image 89
Chenna Reddy Avatar answered Oct 01 '22 15:10

Chenna Reddy


PrefixIcon:

An icon that appears before the prefixText and before the editable part of the text field, within the decoration's container.

Below code will work for question

TextField(
  decoration: InputDecoration(
    prefixIcon: Icon(Icons.mail),
  ),
);

If we want to arrange icon with some padding we can do like:

 prefixIcon: Padding(
          padding: const EdgeInsetsDirectional.only(start: 30.0),
          child: Icon(Icons.access_alarm), // Change this icon as per your requirement
        )
like image 34
Jitesh Mohite Avatar answered Oct 01 '22 15:10

Jitesh Mohite