如何解决在另一页的异步匿名函数中使用初始化的String
您如何在该匿名函数之外的其他任何地方使用String theFlag
我不得不将其设为匿名函数,因为我无法将单独的异步函数指向onPressed
中的RaisedButton
,因为它仅与onChanged
一起使用,现在我只需要传递{ {1}}到另一个屏幕上的另一个小部件
请帮助和介意初学者的问题
String theFlag
解决方法
您可以这样做,
String iCanBeAcessed; //make this variable somewhere else,so that you can use it anywhere.
//Inside your anonymous function
iCanBeAcessed=theFlag;
我该怎么用?
您可以在类外声明它,并且可以在项目中的任何地方使用它。 例子,
//imports
String iCanBeAcessed;
class yourClassName{
//All your other functions and build method
现在,以以下方式导入dart文件(在其中已声明iCanBeAcessed的位置)。
import dartFile.dart as flagString;
//Now,you can use this variable anywhere!
Text(flagString.iCanBeAcessed),
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。