确保函数在应用程序关闭之前结束-Flutter

发布于 2025-01-22 01:38:57 字数 124 浏览 2 评论 0原文

我正在使用flutter制作一个具有缓存数据库的应用程序。更新过程在从服务器插入新数据之前会截断表。

当前,如果我在运行更新功能时关闭应用程序,则更新在中间中断,并且数据未完全更新。

我该如何避免这种情况?

I'm making an app using flutter, that has a cache Database. The update process Truncates the tables before inserting new data from the server.

Currently, If I close the app while the update function is running, The update is interrupted in middle and the data is not completely updated.

How Can I avoid this?

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

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

发布评论

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

评论(1

烂人 2025-01-29 01:38:58

使用application_state标志

您可以创建一个表格,该表不会被更新一个调用迁移>迁移更新
在启动更新之前
更新完成后,更改为更新
每当您打开应用程序时,请查看application_state更新,以再次重新运行您的更新。
请注意,您也可以使用此表来跟踪用户更新,使用timeSteps或其他逻辑...

Use an application_state flag

You can create a table that doesn't get truncated with the update a call it migrations or updates .
Before you start an update insert a record in that table with a flag called application_state with value updating.
When your update is completed change it's value to updated.
Whenever you open your app , see if application_state is updating , to rerun your update again because it failled .
Note that you can use this table to track user updating too, using timesteps or some other logic ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文