[FLUTTER]:如何在TextField中输入depecoration中启用/禁用errortext属性?

发布于 2025-02-06 20:30:00 字数 1228 浏览 0 评论 0原文

当表单的输入不尊重允许字符时,我需要激活错误消息。 我该怎么做?

我尝试了 errortext ,但是如果它处于活动状态,则即使输入正确,该错误仍然存​​在。 我需要仅在表单为空的时出现错误消息,并且当字符输入不匹配时。


    child: TextField(
                                    controller: state.registrySizeTxtEditCtrl,
                                    decoration: InputDecoration(
                                      errorText: errText,
                                      enabled: state.revocation,
                                      labelText: 'Registry Size',
                                      hintText: '0 - 1000',
                                      border: OutlineInputBorder(
                                        borderRadius:
                                            BorderRadius.circular(7.0),
                                      ),
                                    ),
                                    keyboardType: TextInputType.none,
                                    inputFormatters: <TextInputFormatter>[
                                      FilteringTextInputFormatter.allow(
                                          RegExp(r'^([0-9][0-9]{0,2}|1000)$')),
                                    ],),



I need to activate an error message when the input of the form does not respect the allowed characters.
How can I do that?

I tried errortext, but if it is active, the error remains even when the input is right.
I need the error message to appear only when the form is empty and when the characters entered do not match the format.


    child: TextField(
                                    controller: state.registrySizeTxtEditCtrl,
                                    decoration: InputDecoration(
                                      errorText: errText,
                                      enabled: state.revocation,
                                      labelText: 'Registry Size',
                                      hintText: '0 - 1000',
                                      border: OutlineInputBorder(
                                        borderRadius:
                                            BorderRadius.circular(7.0),
                                      ),
                                    ),
                                    keyboardType: TextInputType.none,
                                    inputFormatters: <TextInputFormatter>[
                                      FilteringTextInputFormatter.allow(
                                          RegExp(r'^([0-9][0-9]{0,2}|1000)
)),
                                    ],),



如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文