颤音中的小键只显示一次

发布于 2025-02-10 08:09:32 字数 121 浏览 3 评论 0原文

如果文本字段中给出的输入不正确(例如字段仅接受整数而不是字符或字符串),我想发出错误警告。我已经用过了 get.snackbar给出错误警告。但是打开应用程序后仅显示一次。如何解决此问题{预先感谢}

I want to give an error warning if the input given in the text field is not correct (like the field only accepts integer and not characters or strings). I have used
Get.snackbar for giving the error warning . but it show only once after opening the application. How to solve this issue {Thanks in advance}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拧巴小姐 2025-02-17 08:09:32

首先为您的Snackbar创建标题作为字符串

String? sbTitle;

,然后您可以创建一个函数,该函数每次调用时都可以显示Snackbar

void showSnackBar(BuildContext context) {
  final scaffold = ScaffoldMessenger.of(context);
  scaffold.showSnackBar(
    SnackBar(
      content: Text(sbTitle!),
      action: SnackBarAction(
          label: 'Ok', onPressed: scaffold.hideCurrentSnackBar),
    ),
  );
}

,最后每次您要显示和错误时,只需将标题设置为错误代码,然后将其传递到这样的函数中

 sbTitle = "Invalid input";
 showSnackBar(context);

这将为您节省很多时间

first create a title for you snackbar as a string

String? sbTitle;

then you can create a function which can show snackBar every time you call it

void showSnackBar(BuildContext context) {
  final scaffold = ScaffoldMessenger.of(context);
  scaffold.showSnackBar(
    SnackBar(
      content: Text(sbTitle!),
      action: SnackBarAction(
          label: 'Ok', onPressed: scaffold.hideCurrentSnackBar),
    ),
  );
}

and finally every time you want to show and error just set the title to your error code and pass in the function like this

 sbTitle = "Invalid input";
 showSnackBar(context);

this will save you so much time cause you dont have to build snackbar every time you want to show snackbar

清风不识月 2025-02-17 08:09:32

我尝试了Snackbar小部件作为功能。它起作用了!!!

I tried the SnackBar widget as a function. it worked!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文