disableNetwork method

Future<void> disableNetwork()

Disables network access for this instance. While the network is disabled, any snapshot listeners or get() calls will return results from cache, and any write operations will be queued until network usage is re-enabled via a call to enableNetwork.

Returns a Future that will be completed once networking is disabled.

While the network is disabled, a DocumentReference.get of a document that is not in the cache fails with FirestoreErrorCode.unavailable, the futures of writes do not complete, and transactions and aggregations fail.

await firestore.disableNetwork();
// Answered from the cache; the write is sent later.
final DocumentSnapshot<Map<String, Object?>> cached = await firestore
    .doc('cities/SF')
    .get();
print(cached.metadata.isFromCache); // true
unawaited(firestore.doc('cities/SF').update({'visited': true}));
await firestore.enableNetwork();

Implementation

Future<void> disableNetwork() {
  return client.disableNetwork();
}