【问题标题】:In my flutter app, i have 2 functions .. the second one debends on the first one but the problem is the second one executed before the first one在我的颤振应用程序中,我有两个功能..第二个取决于第一个,但问题是第二个在第一个之前执行
【发布时间】:2021-11-27 10:32:49
【问题描述】:

我尝试了异步,等待但不工作 然后我尝试了 then & whenCompleted 但也没有工作..

我做了一个将图像上传到 Firebase 存储的功能 并将链接放在列表中 this is the first function source code

在这里,我使用此功能存储带有图片链接的帖子到 Firestore the second function

最后我做了这个函数来在第一个函数完成后执行第二个函数 third function

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: flutter flutter-layout flutter-dependencies flutter-test


【解决方案1】:

您可以尝试将调用函数,即publishPost 设为void 而不是Future。此外,删除 async 和 await 关键字,因为在 async-await 的情况下,这两个函数,即 uploadPostImagesuploadPost 几乎同时运行。如果删除async-await,它基本上会阻塞应用程序的流程,直到uploadPostImages 完成。然后它继续到uploadPosts。或者你可以这样做:

void publishPost({<function-parameters>}) {
     uploadPostImages({<function-parameters>}).then((value) {
         uploadPost({<function-parameters>});
     }
     ...
}

【讨论】:

    猜你喜欢
    • 2018-12-03
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 2023-03-18
    相关资源
    最近更新 更多