[英]how to pass a variable value from one flutter page to another
suppose, I have a file body1.dart where I created a variable "hello" which was initially empty!假设,我有一个文件 body1.dart,我在其中创建了一个变量“hello”,它最初是空的!
String hello = "";
Now, in the same file, I have created a loop which will set and update the value of hello after every iteration!现在,在同一个文件中,我创建了一个循环,它将在每次迭代后设置和更新 hello 的值!
Now the thing is whenever the value of "hello" get changed, I want to display that inside a Text Field which is in a different file body2.dart.现在的问题是,每当“hello”的值发生变化时,我想在另一个文件 body2.dart 中的文本字段中显示它。 I want to retrieve the real-time value at that exact moment!
我想在那一刻检索实时值! (Not the final outcome at the end of the loop)
(不是循环结束时的最终结果)
Can you provide code snippet for this?你能为此提供代码片段吗? So that we can best assist you.
以便我们能够为您提供最好的帮助。
Otherwise the best option would be to use a stream.否则最好的选择是使用流。 You can have multiple dart classes subscribed to the same stream.
您可以让多个 dart 类订阅同一个流。
Streams provide an asynchronous sequence of data.流提供异步数据序列。 Data sequences include user-generated events and data read from files.
数据序列包括用户生成的事件和从文件中读取的数据。 You can process a stream using either await for or listen() from the Stream API
您可以使用 Stream API 中的 await for 或 listen() 来处理流
Checkout official documentation from dart.dev从 dart.dev 查看官方文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.