【问题标题】:Flutter - Textfield label overflow cutting off textFlutter - 文本字段标签溢出切断文本
【发布时间】:2020-06-01 04:51:33
【问题描述】:

我正在做一个 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,
        ),

【问题讨论】:

  • 您好,感谢您的回复,我认为这不适用于文本字段标签,
  • 为什么不喜欢普通的html,你添加一个标题属性,当有人将鼠标悬停在它上面时,标签就会出现,一个技巧。
  • 我确信labelText: "A VERY VERY VERY VERY VERY VERY LONG LABEL", 需要一个字符串,你不能给它分配一个小部件
  • maxLines 属性可用于您的示例中提到的TextFormField。检查这个,stackoverflow.com/questions/45900387/… 和这个,stackoverflow.com/questions/43348254/…

标签: flutter


【解决方案1】:

我在尝试解决相同问题时找到了this solution。尝试使用 decoration 属性并将 errorMaxLines 属性设置为大于 1 的数字。 例如

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

【讨论】:

  • 您提供的解决方案是关于错误文本而不是labelText
猜你喜欢
  • 2018-03-19
  • 2021-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-28
  • 1970-01-01
  • 2011-11-18
  • 2020-06-01
相关资源
最近更新 更多