Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter TextField align text at the top

I have a TextField like this:

enter image description here

I want the hint and the text to be aligned at the top, not in the center.

I tried textAlign: TextAlign.start but that is just for the horizontal alignment.

TextField(
  textAlign: TextAlign.start,
  expands: true,
  maxLines: null,
  decoration: InputDecoration(
      border: OutlineInputBorder(
        borderRadius: BorderRadius.circular(3),
      ),
      hintText: 'Enter Unicode text'),
),

How to I make the text go to the top?

I found the answer so I am adding this as a self-answer Q&A.

like image 908
Suragch Avatar asked Jan 05 '20 13:01

Suragch


2 Answers

To align the text inside of a TextField to the top, use

textAlignVertical: TextAlignVertical.top

This will give you what you want:

enter image description here

TextField(
  textAlignVertical: TextAlignVertical.top,
  expands: true,
  maxLines: null,
  decoration: InputDecoration(
      border: OutlineInputBorder(
        borderRadius: BorderRadius.circular(3),
      ),
      hintText: 'Enter Unicode text'),
)
like image 117
Suragch Avatar answered Nov 15 '22 11:11

Suragch


Add alignLabelWithHint: true,


TextFormField(
  maxLines: 10,
  minLines: 5,
  decoration: InputDecoration(
      border: OutlineInputBorder(
        borderRadius: BorderRadius.circular(3),
      ),
      hintText: 'Enter Unicode text'),
      alignLabelWithHint: true,
)
like image 34
Techalgoware Avatar answered Nov 15 '22 11:11

Techalgoware