我正在尝试将数据作为临时存储在应用程序中 1 小时。
我正在从 Firestore 获取数据:
static final FirebaseFirestore _firestore = FirebaseFirestore.instance;
Future<List<DocumentSnapshot>> fetchLeaderBoard() async {
final result =
await _firestore.collection('users').orderBy('points', descending: true).limit(10).get();
return result.docs;
}
为了将其存储到 HiveDb,我已经完成了:
class _LeaderBoardState extends State<LeaderBoard> {
var _repository;
List<DocumentSnapshot> users;
Box box;
@override
void initState() {
_repository = Repository();
users = [];
super.initState();
openBox();
}
Future openBox() async {
var dir = await path_provider.getApplicationDocumentsDirectory();
Hive.init(dir.path);
box = await Hive.openBox('leaderBoard');
return;
}
Future<void> _fetchUsers() async {
users = await _repository.fetchLeaderBoard();
box.put('users',users);
print("HIVE DB : ");
print(box.get('users'));
}
}
现在,如何从 Hivedb 获取 1 小时的时间?1 小时后,应再次从 Firestore 获取数据。