Flutter TextFormField验证器文本太长

huangapple go评论53阅读模式
英文:

Flutter TextFormField validator text is too long

问题

我有一个小容器内的TextFormField。问题是我的验证消息文本太长,以至于它被截断。

如何解决这个问题?我需要用户能够阅读整个文本。如何使消息像滚动文本一样移动,或者通过自动减小字体大小来适应文本?

我不知道,求帮助。任何建议都可以。

谢谢

TextFormField(
  style: const TextStyle(color: Colors.white),
  controller: _newForeignController,
  decoration: InputDecoration(
    fillColor: Colors.black26,
    filled: true,
    hintStyle: const TextStyle(color: Colors.white24),
    hintText: "在这里输入新单词",
    border: OutlineInputBorder(
      borderSide: BorderSide.none,
      borderRadius: BorderRadius.circular(8)),
  ),
  validator: (value) {
    if (value!.isEmpty) {
      return '这是一个太长以至于无法在应用中显示的警告消息';
    }
    return null;
  },
),
英文:

So I have this TextFormField inside a small container. The problem is my validator message text it too long for the container so it just get cut.

How can I get around this problem ? I need the user able to read the whole text. How to make the message moving as like a running text or just fit the text by making making the font size smaller automatically ?

I dont know, please help me. Any suggestion will do for me

Thank you

                TextFormField(
                  style: const TextStyle(color: Colors.white),
                  controller: _newForeignController,
                  decoration: InputDecoration(
                    fillColor: Colors.black26,
                    filled: true,
                    hintStyle: const TextStyle(color: Colors.white24),
                    hintText: "New word here",
                    border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                        borderRadius: BorderRadius.circular(8)),
                  ),
                  validator: (value) {
                    if (value!.isEmpty) {
                      return 'This is a warning that too long to display in the app';
                    }
                    return null;
                  },
                ),

答案1

得分: 1

只需根据您的需要添加errorMaxLines,它表示错误文本可以占据多少行:

TextFormField(
  style: const TextStyle(color: Colors.white),
  controller: _newForeignController,
  decoration: InputDecoration(
    fillColor: Colors.black26,
    filled: true,
    hintStyle: const TextStyle(color: Colors.white24),
    hintText: "在这里输入新单词",
    errorMaxLines: 6,
    border: OutlineInputBorder(
      borderSide: BorderSide.none,
      borderRadius: BorderRadius.circular(8),
    ),
  ),
  validator: (value) {
    if (value.isEmpty) {
      return '这是一个警告,内容太长无法在应用中显示,这是一个警告,内容太长无法在应用中显示,这是一个警告,内容太长无法在应用中显示';
    }
    return null;
  },
)

Flutter TextFormField验证器文本太长

英文:

Just add errorMaxLines as per your need, It indicates how many line can error text occupy:

TextFormField(
                    style: const TextStyle(color: Colors.white),
                    controller: _newForeignController,
                    decoration: InputDecoration(
                      fillColor: Colors.black26,
                      filled: true,
                      hintStyle: const TextStyle(color: Colors.white24),
                      hintText: "New word here",
                      errorMaxLines: 6,
                      border: OutlineInputBorder(
                        borderSide: BorderSide.none,
                        borderRadius: BorderRadius.circular(8),
                      ),
                    ),
                    validator: (value) {
                      if (value!.isEmpty) {
                        return 'This is a warning that too long to display in the app,This is a warning that too long to display in the app,This is a warning that too long to display in the app';
                      }
                      return null;
                    },
                  ),

Flutter TextFormField验证器文本太长

huangapple
  • 本文由 发表于 2023年2月27日 16:12:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578082.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定