Flutter -文本域标签溢出切断文本

wljmcqd8  于 2023-05-01  发布在  Flutter
关注(0)|答案(3)|浏览(148)

我正在做一个Flutter项目,我用TextFormField实现了一个表单,我们有一些标签很长的字段,因为它们太长了,Flutter我们剪切文本并添加。..最后,是否可以设置溢出,使标签文本为2行,而不是切断文本?

TextFormField(
          key: GlobalKey(),
          controller: _textEditingController,
          focusNode: _focusNode,
          obscureText: true,
          keyboardType: TextInputType.text,
          textInputAction: TextInputAction.done,
          decoration: widget.decorations.copyWith(
            errorText:
                widget.field["error"] != null ? widget.field["error"] : null,
            labelText: "A VERY VERY VERY VERY VERY VERY LONG LABEL",
            hintText: widget.field["helpText"],
            helperStyle: TextStyle(
              color: Colors.black,
            ),
          ),
          onFieldSubmitted: widget.onFieldSubmitted,
          onSaved: widget.onSaved,
          onTap: widget.onTap,
        ),
r1zhe5dt

r1zhe5dt1#

我发现this solution当我试图解决同样的问题。请尝试使用decoration属性,并将errorMaxLines属性设置为大于1的数字。例如:

TextField(
     keyboardType: TextInputType.number,
     decoration: InputDecoration(
     errorMaxLines: 2,),)
jtoj6r0c

jtoj6r0c2#

对我很有效。...
文本表单字段(

decoration: InputDecoration(
 label: Text(
      "A VERY VERY VERY VERY VERY VERY LONG LABEL",
    ),)
bd1hkmkf

bd1hkmkf3#

其他的答案我都想了,这是唯一一个对我有用的。容器有一个transform属性,允许我们使用负边距,在装饰中使用它可以为两行标签给予更多的空间,而不会侵占您的字段。

decoration: InputDecoration(
    contentPadding: EdgeInsets.only(top: 5, bottom: 5),
    label: Container(
      transform: Matrix4.translationValues(0.0, -15.0, 0.0),
      child: const Text(
          'Label text here. This also allows you to have long lable text as you can use the space for 2 lines.'),
    ),
  ),

相关问题