我可以手动将Flutter中Firestore的数据源设置为仅来自Cache吗?
我打算使用 Flutter 重新创建我的原生 Android 和 iOS 应用程序,因此在深入研究 Flutter 之前,我想确保我需要的一切都可以在 Flutter 上使用。
因此,在原生 Android 和 iOS 中,我可以手动设置我的数据是来自 Firestore 服务器还是来自使用 Kotlin 代码的缓存,以强制系统仅从缓存中获取数据,而不是从服务器获取数据。
db.document(path).get(Source.CACHE).addOnSuccessListener {
}
我可以使用 FlutterFire 在 Flutter 中拥有相同的行为吗?我试图阅读此处的文档,但找不到。
在我看来 FlutterFire 中的文档不如这里的native 文档完整。例如,可以像这里的答案一样使用 Field Value 进行更新,但我在 FlutterFire 文档中找不到它。
我错过了什么吗?我是 Flutter 的新手 🙂
回答
对的,这是可能的。我们可以参考发布链接和文档链接。
DocumentSnapshot snapshot = await FirebaseFirestore.instance
.collection("collection_name")
.doc("document_name")
.get(GetOptions(source: Source.cache));
/// Reads the document referenced by this [DocumentReference].
///
/// By providing [options], this method can be configured to fetch results only
/// from the server, only from the local cache or attempt to fetch results
/// from the server and fall back to the cache (which is the default).
Future<DocumentSnapshot> get([GetOptions options]) async {
return DocumentSnapshot._(
firestore, await _delegate.get(options ?? const GetOptions()));
}
THE END
二维码