'showSnackBar'已过时,不应使用

编程入门 行业动态 更新时间:2024-10-22 18:33:28
本文介绍了'showSnackBar'已过时,不应使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

试图弄清楚这个颤动的问题.下面的代码不推荐使用showSnackbar,并且正在尝试解决此问题.第二个代码是我尝试解决的问题.未为类型'ScaffoldState'定义吸气剂'ScaffoldMessenger'"提出了一个新问题.该错误告诉我要导入material.dart文件,但该文件已被导入.

Trying to figure out this flutter problem. The below code has the showSnackbar as deprecated, and am trying to figure out with the fix is. The second code is my attempt to fix the problem. A new problem comes up with "The getter 'ScaffoldMessenger' isn't defined for the type 'ScaffoldState'.". The error tells me to import material.dart file but it is already imported.

感谢您的帮助.

Padding( padding: const EdgeInsets.all(10.0), child: GestureDetector( onTap: ()async{ if(!await authProvider.signIn()){ _key.currentState.showSnackBar( SnackBar(content: Text("Login failed")) ); } }, Padding( padding: const EdgeInsets.all(10.0), child: GestureDetector( onTap: ()async{ if(!await authProvider.signIn()){ _key.currentState.ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text("Login failed")) ); } },

推荐答案

基于此处的文档,看起来新的ScaffoldMessenger可以处理其下面的所有SnackBar.如果您没有多个ScaffoldMessengers,则应该可以致电:

Based on the documentation here, it looks like the new ScaffoldMessenger handles all SnackBars below it. If you don't have multiple ScaffoldMessengers, you should just be able to call:

ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Login failed")));

更多推荐

'showSnackBar'已过时,不应使用

本文发布于:2023-11-14 10:10:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586931.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不应   showSnackBar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!