【问题标题】:How to automatically update cached data in HiveBox(Flutter) from API once a day如何每天一次从API自动更新HiveBox(Flutter)中的缓存数据
【发布时间】:2023-02-05 12:37:31
【问题描述】:

我在我的 flutter 应用程序中使用 Hive 存储数据。当来自 API(airtable)的远程数据发生更改但我的应用程序继续存储旧数据时,我遇到了一些问题。 例如,如何每 1 天自动更新我的应用程序?

有一个我如何使用 Hive 的例子。

await Hive.initFlutter();
var box = await Hive.openBox('wiseBox');

if(box.isEmpty) {
    //when my app was open by user at the first
    await _save();
} 
else {
    //repeatedly
    await _openCashedData();
}


_save() async {
  await box.put('data', 'some_data');
}

_openCashedData() async { // <- can be a synchronous function
  await box.get('data');
}

【问题讨论】:

    标签: android flutter flutter-hive airtable


    【解决方案1】:

    每次启动应用程序以及应用程序返回前台时,您都可以更新 Hive 数据。您存储最后一次数据更新的日期,如果超过一天则更新。

    当应用程序“恢复”时,检查这个是否被捕获

    https://levelup.gitconnected.com/lets-utilize-the-flutter-app-lifecycle-388121533fd9

    【讨论】:

    • 你好!抱歉,您的链接无效。你能再发一次吗?
    • @SaturnPro 在 Google 上查看“Flutter App LifeCycle State”。您可以在应用程序“恢复”、“不活动”、“暂停”或“分离”时捕捉到 dev.to/prakashselvaraj/flutter-app-life-cycle-1jim
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多