Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically center text in text field in Flutter

Tags:

flutter

dart

I'm creating a login screen with fields for username and password, but the text always seems a little bit off to the top(see image).

Image of the Issue

How it should look (did with Photoshop)

How can i fix this?

Here is code for the TextFormField:

new Padding(                     padding: const EdgeInsets.symmetric(vertical: 8.0),                     child: new TextFormField(                       maxLines: 1,                       controller: controller,                       validator: (value) {                         if (value.isEmpty) {                           return 'Please enter username.';                         }                       },                       decoration: new InputDecoration(                           labelText: 'Username',                           suffixIcon: new IconButton(                             highlightColor: Colors.transparent,                             icon: new Container(                                 width: 36.0, child: new Icon(Icons.clear)),                             onPressed: () {                               controller.clear();                             },                             splashColor: Colors.transparent,                           ),                           prefixIcon: new Icon(Icons.account_circle)),                     ),                   ), 

And here is my general theme code, if that helps^^

new ThemeData(     fontFamily: 'Product Sans',     brightness: Brightness.dark,     buttonColor: Colors.green[300],     accentColor: Colors.green[300],     scaffoldBackgroundColor: Colors.blueGrey[900],     canvasColor: Colors.blueGrey[900],     textSelectionColor: new Color.fromRGBO(81, 107, 84, 0.8),     bottomAppBarColor: Colors.blueGrey[800],     primaryColor: Colors.blueGrey[900],     indicatorColor: Colors.green[300],     cardColor: Colors.white,     highlightColor: Colors.green[300],     errorColor: Colors.red[400],     textSelectionHandleColor: Colors.green[300],     splashColor: Colors.white10,     buttonTheme: new ButtonThemeData(         shape: new RoundedRectangleBorder(             borderRadius: new BorderRadius.circular(22.0))),     inputDecorationTheme: new InputDecorationTheme(         contentPadding:             new EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),         border: new OutlineInputBorder(             gapPadding: 3.0,             borderRadius: new BorderRadius.circular(22.0))),   ), 
like image 757
leodriesch Avatar asked May 29 '18 19:05

leodriesch


People also ask

How do I center text in a TextField?

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

You can try with contentPadding (.all or .only)

TextFormField( ... decoration: InputDecoration(     contentPadding: EdgeInsets.all(10.0), ... ) 

before enter image description here

afterenter image description here

like image 189
silvaric Avatar answered Sep 18 '22 02:09

silvaric