flutterflutter-layouttextfield

How to change TextField's height and width?


How to customise TextField's width and height?


Solution

  • To adjust the width, you could wrap your TextField with a SizedBox widget, like so:

    const SizedBox(
      width: 100.0,
      child: TextField(),
    )
    

    I'm not really sure what you're after when it comes to the height of the TextField but you could definitely have a look at the TextStyle widget, with which you can manipulate the fontSize and/or height

    const SizedBox(
      width: 100.0,
      child: TextField(
        style: TextStyle(fontSize: 40.0, height: 2.0, color: Colors.black),
      ),
    )
    

    Bear in mind that the height in the TextStyle is a multiplier of the font size, as per comments on the property itself:

    The height of this text span, as a multiple of the font size.

    When [height] is null or omitted, the line height will be determined by the font's metrics directly, which may differ from the fontSize. When [height] is non-null, the line height of the span of text will be a multiple of [fontSize] and be exactly fontSize * height logical pixels tall.

    Last but not least, you might want to have a look at the decoration property of you TextField, which gives you a lot of possibilities

    EDIT: How to change the inner padding/margin of the TextField

    You could play around with the InputDecoration and the decoration property of the TextField. For instance, you could do something like this:

    const TextField(
      decoration: InputDecoration(
        contentPadding: EdgeInsets.symmetric(vertical: 40.0),
      ),
    )