确保函数在应用程序关闭之前结束-Flutter
我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
application_state
标志您可以创建一个表格,该表不会被更新一个调用
迁移>迁移
或更新
。在启动更新之前
更新完成后,更改为
更新
。每当您打开应用程序时,请查看
application_state
是更新
,以再次重新运行您的更新。请注意,您也可以使用此表来跟踪用户更新,使用
timeSteps
或其他逻辑...Use an
application_state
flagYou can create a table that doesn't get truncated with the update a call it
migrations
orupdates
.Before you start an update insert a record in that table with a flag called
application_state
with valueupdating
.When your update is completed change it's value to
updated
.Whenever you open your app , see if
application_state
isupdating
, 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 ...