Reputation: 13803
I am planning to recreate my native Android and iOS app using Flutter, so before I dive deep into Flutter I want to ensure everything I need is available on Flutter.
so, in native Android and iOS, I can manually set if my data comes from Firestore server or from cache using Kotlin code like this to force the system to get data only from cache, not from the server.
db.document(path).get(Source.CACHE).addOnSuccessListener {
}
can I have the equivalent behavior in Flutter using FlutterFire? I have tried to read the documentation in here , but I can't find it.
it seems to me that the documentation in FlutterFire is not as complete as the documentation for native in here. for example, updating using Field Value is possible like the answer in here, but I can't find it in FlutterFire documentation.
am I missing something? I am new in Flutter :)
Upvotes: 4
Views: 1240
Reputation: 980
Yes, it is possible. We can refer to pub link and document link.
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()));
}
Upvotes: 5