简体   繁体   English

如何将变量值从一个颤动页面传递到另一个页面

[英]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.

相关问题 无法在 Flutter 中将变量值从一个无状态 Widget 传递到另一个 - Cannot pass variable value from one stateless Widget to another in Flutter 在颤振中将一个变量值传递给另一个变量 - pass one variables value to another variable in flutter Flutter,如何将值从一个 function 传递到另一页上的另一个 function - Flutter, How to pass value from one function to another function on a different page 如何使用 flutter 将数据从一页传递到另一页? - How to pass data from one page to another with flutter? 如何在 flutter 上将字符串从一页传递到另一页? - How to pass a string from one page to another on flutter? 如何在颤振中将多个参数从一个页面传递到另一个页面 - How to pass many parameters from one page to another in flutter 在 Flutter 中将数据从一个页面传递到另一个页面 - Pass data from one page to another in Flutter 如何将 onTap() 的值从页面传递到另一个 dart/flutter - how to pass value of onTap() from a page to another dart/flutter 如何将值从一个 function 传递到 flutter 中的另一个? - How to pass value from one function to another in flutter? 如何将提供者变量从一个视图页面传递到另一个视图页面以更改其值 - how to pass a provider variable from one view page to another to change its value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM