Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I only apply padding to the text in a TextField in Flutter?

Tags:

flutter

dart

Without padding I get this result:

no padding

With something like this

Padding(padding: EdgeInsets.all(20.0), child: TextField()) 

I get the following result:

with padding

It might be a bit hard to see, but you only have to look at the red badge across the edge to realise what I mean.

I would like to only move the text with my padding, but in reality the whole TextField has the padding applied, i.e. that the underline moves with the padding, but I would like to have the underline still go across the whole view, that only the text inside the TextField is affected by the padding.

like image 457
creativecreatorormaybenot Avatar asked Apr 30 '18 09:04

creativecreatorormaybenot


People also ask

How do you change the TextField padding in Flutter?

You can set the inner padding of a TextField by using the contentPadding property of the InputDecoration class.

How do you give padding to margin and Text in Flutter?

We will use, Padding() and Container() widget to wrap Text() widget and apply padding and margin. Furthermore, you will learn about EdgeInsets method.

How do you reduce the padding in TextField Flutter?

As of flutter 1.17. 5 (and still the same in 2. X) to completely remove or manipulate the padding manually, first you must set isDense: true and then you can adjust the contentPadding as you wanted or apply padding on the parent widget instead. TextField has not an inputDecorationTheme attribute.


1 Answers

To apply the padding to the content of the TextField. You can apply the

contentPadding property of ItemDecoration at decoration property of TextField.

Like this:

TextField(   textAlign: TextAlign.left,   decoration: InputDecoration(     hintText: 'Enter Something',     contentPadding: EdgeInsets.all(20.0),   ), ) 
like image 108
Dhrumil Shah - dhuma1981 Avatar answered Oct 15 '22 01:10

Dhrumil Shah - dhuma1981