简体   繁体   English

Flutter 错误:未定义名称“ScaffoldMessenger”

[英]Flutter error : Undefined name 'ScaffoldMessenger'

Always getting this error on a project without any reason for the moment could you help me on this.总是在没有任何理由的情况下在项目中出现此错误,您能帮我解决这个问题吗?

Undefined name 'ScaffoldMessenger'.未定义名称“ScaffoldMessenger”。 Try correcting the name to one that is defined, or defining the name.尝试将名称更正为已定义的名称,或定义名称。

Flutter version: 1.22.5 stable Flutter版本:1.22.5稳定

Could you help me on this please?你能帮我解决这个问题吗?

If you are still experiencing this issue you might have to update your Flutter sdk .如果您仍然遇到此问题,您可能需要更新您的Flutter sdk

ScaffoldMessenger was first released to Flutter stable channel the 3th of March 2021... ScaffoldMessenger于 2021 年 3 月 3 日首次发布到Flutter稳定频道...

To update flutter just run要更新 flutter 只需运行

flutter upgrade

on your terminal/command line.在您的终端/命令行上。

For further details take a look at the ScaffoldMessenger documentation or in StackOverflow see this thread .有关更多详细信息,请查看ScaffoldMessenger 文档在 StackOverflow 中查看此线程

According to https://flutter.dev/docs/release/breaking-changes (at the moment), under Not yet released to stable , we see SnackBars managed by the ScaffoldMessenger .根据https://flutter.dev/docs/release/break-changes (目前),在Not yet release to stable下,我们看到SnackBars 由 ScaffoldMessenger 管理 So, it's not in 1.22... it'll be in the next release.所以,它不在 1.22 中……它将在下一个版本中。

Got the same error and I tried this and it work得到了同样的错误,我试过了,它工作

       Scaffold.of(context).showSnackBar(
          SnackBar(
             content: Text('Some Text'),
                  ),
                 );

If you get an error that scaffold is not present then, use builder widget to get the context and then use the scaffold.of() part.如果您收到脚手架不存在的错误,请使用构建器小部件获取上下文,然后使用脚手架.of() 部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM