如何将数据从一个将来的任务发送到扑朔迷离的另一任务?

发布于 2025-02-09 10:07:41 字数 446 浏览 3 评论 0原文

例如,扑朔迷离中有4个未来的任务彼此依赖,并且在完成这些任务后navigator.pushreplacement被调用以更改功能。通过依赖,这意味着一个未来的返回价值是其他未来任务的论点。

Future<int> f1() async{}
Future<String> f2(int i) async{}
Future<bool> f3(String s) async{}
Future<int> f4(bool b) async{}

F2的参数是F1的返回值,F3的参数是F2的返回值,F4的参数为F3的返回值。这意味着在F1完成之前不应执行F2,直到F2完成后才执行F3,并且在F3完成之前不应执行F4。 这些都完成后,应调用navigator.pushreplacement更改页面。我该如何实现?

For example there are 4 Future tasks in flutter that are dependent on each other and after these tasks are completed Navigator.pushReplacement is called to change function. By dependent it means that return value of one Future is the argument of other Future task.

Future<int> f1() async{}
Future<String> f2(int i) async{}
Future<bool> f3(String s) async{}
Future<int> f4(bool b) async{}

The argument of f2 is return value of f1, argument of f3 is return value of f2 and argument of f4 is return value of f3. Which means f2 should not be executed until f1 is completed, f3 should not be executed until f2 is completed and f4 should not be executed until f3 is completed.
After these all are completed Navigator.pushReplacement should be called to change page. How do I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽你眉间 2025-02-16 10:07:41
  Future<int> f1() async{
    int i=1;
    return i;
  }
  Future<String> f2(int i) async{
    String string='string';
    return string;
  }
  Future<bool> f3(String s) async{
    bool val=true;
    return val;
  }
  Future<int> f4(bool b) async{
    int i=1;
    return i;
  }
  ///create a function to execute the above 4 futures in order
  function()async{
    f1().then((f1_return) {
      f2(f1_return).then((f2_return){
        f3(f2_return).then((f3_return) {
          f4(f3_return).then((f4_value) {
            ///add your Navigator.pushReplacement method here
          });
        });
      });
    });
  }
  Future<int> f1() async{
    int i=1;
    return i;
  }
  Future<String> f2(int i) async{
    String string='string';
    return string;
  }
  Future<bool> f3(String s) async{
    bool val=true;
    return val;
  }
  Future<int> f4(bool b) async{
    int i=1;
    return i;
  }
  ///create a function to execute the above 4 futures in order
  function()async{
    f1().then((f1_return) {
      f2(f1_return).then((f2_return){
        f3(f2_return).then((f3_return) {
          f4(f3_return).then((f4_value) {
            ///add your Navigator.pushReplacement method here
          });
        });
      });
    });
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文