试图弄清楚这个颤动的问题.下面的代码不推荐使用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'已过时,不应使用
发布评论