TextField的输入文本变满后会减半吗?

时间:2020-07-07 06:11:55

标签: flutter flutter-layout

Screenshot of the problem

我正在尝试添加一封电子邮件,这是一个长文本,但是当文本字段填满时,它将所有文本切成两半。 这是我的代码:

        Container(
            height: 45,
            decoration: BoxDecoration(
            color: HexColor(MyColors.white),
            ),
            child: TextFormField(
            controller: _email,
            maxLength: 100,                        
           autofocus: true,
           validator: validateEmail,
           keyboardType: TextInputType.emailAddress,
           decoration: InputDecoration(
           labelText: 'Email',
           counterText: "",
           border: OutlineInputBorder(),
          ),
         ),
       ),

2 个答案:

答案 0 :(得分:1)

我明白了..您的问题是文字太高了..您可以设置

只需调整contentPadding顶部底部,使其居中即可

decoration: InputDecoration(
                 contentPadding:
                  const EdgeInsets.only(
                  left: 8.0,
                  bottom: 8.0,
                  top: 8.0)),```

答案 1 :(得分:0)

我认为您的问题之所以发生,是因为您使用错误的方式使用了Container,因此您的Container覆盖了TextFormField。因此,我认为您可以使用Container,但要使用最少的属性或完全不用属性。但是,我更喜欢不使用Container

此外,如果您想将maxLines设置得很长,也可以将其添加为null

您的代码应类似于:

TextFormField(
            maxLines: null,
            controller: _email,
            maxLength: 100,
            autofocus: true,
            validator: validateEmail,
            keyboardType: TextInputType.emailAddress,
            decoration: InputDecoration(
              labelText: 'Email',
              counterText: "",
              border: OutlineInputBorder(),
            ),
            style: TextStyle(
              color: Colors.black,
            ),
          ),

此外,您以后可以自行改进设计。 (注意:根据我的代码,我没有使用Container