如何在垂直方向居中对齐TextFormField中的Text和labelText而不影响边框?

时间:2020-08-18 17:15:54

标签: flutter flutter-layout

如果您注意到下面的图像,则标签和文本都将对齐到顶部。

  1. 任何人都可以帮助我们进行对齐以使这两个垂直居中吗?

Sample Image

  1. 此外,如果您注意到“电子邮件”正上方,则边框会被剪切。有人可以帮助代码片段来避免这种情况吗?

  2. 还有什么办法,我们可以根据'TextFormField'的内容(值)进行格式化吗?

以下是产生以上图像的编码。

TextFormField(
  decoration: InputDecoration(
    fillColor: Colors.white,
    filled: true,
    contentPadding: EdgeInsets.all(10.0),
    labelText: 'Email:',
    labelStyle: TextStyle(color: Colors.red, height: 3),
    prefixIcon: Icon(Icons.email_outlined),
    enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: Colors.white, width: 1.0)),
    focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: Colors.red, width: 2.0)),
    prefixStyle: TextStyle(
      inherit: true,
      color: Colors.red,
    ),
 ),

理想情况下,我想要一个像下面的文本框

enter image description here

1 个答案:

答案 0 :(得分:0)

您的代码没问题,只需从labelStyle删除“ height”参数

labelStyle: TextStyle(color: Colors.red),