1

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

这是代码

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),
                                 ),
                               ),

当我添加大量文本时,会发生这种情况:[第一个 ok] [下一个 ???] 在此处输入图像描述

在此处输入图像描述

4

1 回答 1

2

为了使 TextField 的文本正常显示,它需要他的正常高度,在图像下方的图像中,没有给容器提供高度:

在此处输入图像描述

但是如果你给它的高度小于它需要显示的文本,就会发生这种情况(在示例中,设备的高度乘以 0.075):

在此处输入图像描述

要降低 TextField 的高度,您可以更改属性contentPadding或将其设置isDensetrue

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,
  ),
),
于 2020-08-04T15:22:31.890 回答