英文:
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;
},
)
英文:
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;
},
),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论