Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align text of TextFormField to center, vertical in Flutter?

I am new to Flutter Development & tried certain work around but nothing really helped. I want my text to be center vertically in TextFormField in flutter.

textAlign: TextAlign.start brings my text to left but I want them to be center vertically also. textAlign: TextAlign.center brings my text to center but I want them to be start from left also.

This is what I am getting, enter image description here

This is what I want, enter image description here

Snippet of my code:

@override
Widget build(BuildContext context) {
return new Form(
    key: _formKey,
    child: new SingleChildScrollView(
        child: new Theme(
      data: new ThemeData(
          primaryColor: const Color(0xFF102739),
          accentColor: const Color(0xFF102739),
          hintColor: const Color(0xFF102739)),
      child: new Column(
        children: <Widget>[
          new TextFormField(
            textAlign: TextAlign.center,
            maxLines: 1,
            autofocus: true,
            keyboardType: TextInputType.emailAddress,
            style: new TextStyle(
                color: const Color(0xFF0f2638),
                fontFamily: 'ProximaNova',
                fontStyle: FontStyle.italic,
                fontSize: 16.0),
            decoration: new InputDecoration(
                contentPadding: const EdgeInsets.only(
                    top: 8.0, bottom: 8.0, left: 10.0, right: 10.0),
                hintText: "YOUR E-MAIL",
                hintStyle: new TextStyle(
                    color: const Color(0x703D444E),
                    fontFamily: 'ProximaNova',
                    fontStyle: FontStyle.italic,
                    fontSize: 16.0),
                border: new UnderlineInputBorder(
                    borderSide: new BorderSide(
                        color: const Color(0xFF0f2638), width: 0.2))),
            validator: _validateEmail,
          ),
        ],
      ),
    )));
}
like image 314
buzzingsilently Avatar asked May 15 '18 09:05

buzzingsilently


People also ask

How do I align text vertically center in Flutter?

to set center text vertically and horizontally in Flutter Just Use Center() widget. It will set Text to horizontally and vertically Center. The text widget has textAlign property you can give them start, end, center, justify, left, right. We can use Align Widget to set text in center align has alignment property.

How do I center text in a text field?

Right-click the text box for which you want to set vertical alignment. On the shortcut menu, click Format Text Box. In the Format Text Box dialog box, click the Text Box tab. In the Vertical alignment box, select Top, Middle, or Bottom.


1 Answers

TextFormField(
 textAlign: TextAlign.center,
)
like image 181
Ferhat İltaş Avatar answered Sep 22 '22 19:09

Ferhat İltaş