颤振-如果我在文本长度上添加了很多文本,为什么我的文本消失了

时间:2020-08-02 13:53:46

标签: flutter uitextfield flutter-layout flutter-text

如标题中所述;当我在文本字段的长度上添加太多文本时,我的文本“消失”了,为什么会发生这种情况?

这是代码

Container(
                                 height: mediaSize.height * .075,
                                 decoration: BoxDecoration(
                                     borderRadius:
                                         BorderRadius.all(Radius.circular(12.5)),
                                     boxShadow: <BoxShadow>[
                                       BoxShadow(
                                           color: Colors.black54.withOpacity(0.45),
                                           spreadRadius: 1,
                                           blurRadius: 4,
                                           offset: Offset(3.5, 4))
                                     ]),
                                 child: TextFormField(
                                   decoration: InputDecoration(
                                       focusedBorder: OutlineInputBorder(
                                           borderSide:
                                               BorderSide(color: myLightOrangeColor),
                                           borderRadius: BorderRadius.all(
                                               Radius.circular(12.5))),
                                       enabledBorder: OutlineInputBorder(
                                           borderSide: BorderSide(
                                               color: myLightOrangeColor, width: 6),
                                           borderRadius: BorderRadius.all(
                                               Radius.circular(12.5))),
       
                                       labelStyle: TextStyle(color: Colors.black, fontSize: 15, fontWeight: FontWeight.bold),
                                       filled: true,
                                       fillColor: Colors.white),
                                   keyboardType: TextInputType.text,
                                   style: TextStyle(color: Colors.black, fontSize: 15, fontWeight: FontWeight.bold),
                                 ),
                               ),

当我在文本中添加很多内容时,会发生:[第一个确定] [下一个???] enter image description here

enter image description here

1 个答案:

答案 0 :(得分:2)

要使TextField的文本正常显示,需要其正常的高度,在图像下方的图像中,不给Container赋予高度:

enter image description here

但是如果您给它的高度小于需要显示文本的高度(在此示例中,设备的高度乘以0.075):

enter image description here

要减小TextField的高度,可以更改属性contentPadding或将isDense设置为true

TextFormField(
  decoration: InputDecoration(
    isDense: true,
    //contentPadding: EdgeInsets.all(0), //or any padding you want
      ),
  keyboardType: TextInputType.text,
  style: TextStyle(
    color: Colors.black,
    fontSize: 15,
    fontWeight: FontWeight.bold,
  ),
),