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),
),
),
You need to use prefixIcon
attribute instead of icon
like
TextField(
decoration: InputDecoration(prefixIcon: Icon(Icons.mail)),
)
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With