Flutter Firestore "Failed to Get Document Because the Client Is Offline": 4-Step Fix
What does "Failed to get document because the client is offline" mean in Flutter?
It means a single-document get() in cloud_firestore couldn't reach the Firestore backend and found no copy of that document in the local cache, so it threw instead of guessing. Firebase's offline guide states the rule plainly: when you're offline, "an empty result is returned" for a query with no cached documents, but "when fetching a specific document, an error is returned instead." In Flutter the exception usually reads [cloud_firestore/unavailable] Failed to get document because the client is offline. The cause isn't always a dead connection: a wrong emulator host, a web app without persistence or a Source.server read can produce the same message on a working network. This guide was checked against the Firebase docs and the FlutterFire API reference on 2026-12-01.
The Offline Read Check: 4 steps
Short answer: find out which read failed, check whether the device can really reach Firestore, check the cache settings for your platform, then choose the right read source for that screen.
- Find the read. The error only comes from
DocumentReference.get(). A queryget()returns an empty snapshot instead, and asnapshots()listener doesn't throw just because the device is offline. Log the document path so you know which screen triggers it. - Check the connection to Firestore, not just the internet. Confirm the app talks to the right project and host: emulator settings left in a release build, an Android emulator pointed at
localhost, or a network that blocks Firestore's transport all look like "offline" to the SDK. - Check the cache for your platform. On Android and iOS, offline persistence is on by default. On the web it's off by default, so a first read without a network has nothing to fall back on.
- Pick the read source on purpose. Use the default source for normal screens,
Source.cachefor an instant offline view, andSource.serveronly where stale data would be wrong, and catch the error there.
Which read throws, and which doesn't?
Short answer: a single-document get throws when nothing is cached, a server-only read throws whenever the backend is unreachable, and queries return empty instead (checked 2026-12-01).
| Call | Offline, item cached | Offline, nothing cached |
|---|---|---|
doc.get() (default source) | Returns the cached copy | Throws "client is offline" |
doc.get(GetOptions(source: Source.cache)) | Returns the cached copy at once | Throws a FirebaseException |
doc.get(GetOptions(source: Source.server)) | Throws: the cache is skipped | Throws |
query.get() | Returns cached matches | Returns an empty snapshot, no error |
doc.snapshots() | Emits the cached copy | No exception; check metadata.isFromCache before trusting what it shows |
Last checked: 2026-12-01, against the FlutterFire Source enum, which says server causes "an error if the server cannot be reached" and cache throws on a document get when "there is no data in the cache."
The empty query result is the trap behind a second bug: a list screen that shows "no items" offline looks like data loss. Read snapshot.metadata.isFromCache before telling users their list is empty.
Why does it happen with the Firestore emulator?
Short answer: the app is pointed at a host it can't reach, usually localhost from an Android emulator, so every read looks offline.
Firebase's emulator guide says the default host is 127.0.0.1, but "if you are using an Android emulator, you need to use 10.0.2.2," the special address for the host machine. In Flutter that's one line before any other Firestore call:
// Android emulator: 10.0.2.2 reaches the computer running the emulator suite
FirebaseFirestore.instance.useFirestoreEmulator('10.0.2.2', 8080);
Two more emulator checks. The same guide notes the emulator "clears database contents when shut down" while the SDK's offline cache isn't cleared automatically, so stale cached documents can hide a real problem; it suggests disabling local persistence while you test against the emulator. And make sure the emulator call sits behind a debug-only flag, so a release build never tries to reach your laptop. Our list of reasons a Flutter app works in debug but not in release covers that kind of build-only setting.
Why does it happen on Flutter web?
Short answer: persistence is off by default on the web, and some networks block the streaming transport Firestore uses, so the SDK reports offline even though other requests work.
- No cache by default. Firebase's offline guide says that "for the web, offline persistence is disabled by default." Without it, any document read during a network blip has nothing to fall back on.
- Blocked transport. Corporate proxies, antivirus tools and some ad blockers can break Firestore's web channel. The FlutterFire
Settingsclass exposeswebExperimentalForceLongPollingandwebExperimentalAutoDetectLongPollingfor this case. Set them before any other Firestore call, and only one of them: the Firebase JavaScript SDK reference, which FlutterFire web wraps, says forced long-polling can't be used together with auto-detection. - Wrong project config. If
firebase_options.dartpoints at a different project, or a project where Firestore isn't created, reads can stall. Regenerate the options with the FlutterFire CLI, as in our Firebase config match fix.
How should the app handle it?
Short answer: catch the exception on that one read, show cached or placeholder content, and listen instead of polling where the screen needs live data. The same emulator-host mistakes also break Firebase Auth, which fails with a different error; see how to fix firebase_auth/network-request-failed against the Auth emulator.
try {
final snap = await ref.get();
render(snap.data());
} on FirebaseException catch (e) {
if (e.code == 'unavailable') {
showOfflineBanner(); // keep the last data on screen
} else {
rethrow;
}
}
- Prefer a listener for live screens. A
snapshots()stream serves cached data first and updates when the network comes back, and it doesn't fail just because the device is offline. Firebase's guide adds that you needincludeMetadataChanges: trueif you rely on the from-cache flag, because metadata-only changes don't raise events by default. - Warm the cache. Read the documents a screen needs while the device is online, for example the user's profile right after sign-in, so they're in the cache later. The cache has a size threshold (100 MB by default in Firebase's examples) after which older unused documents can be cleaned up.
- Don't confuse it with a rules error. If the app is online and the read is refused, you'll get
permission-denied, which is a different fix: see why Firestore says permission denied in Flutter.
Cache settings also change your read bill and query speed. If offline reads feel slow or your read count jumps, compare with why Firestore reads are too high in a Flutter app. GSPTeck is giosaia's indie studio building mobile and web apps with Flutter and Firebase; see the apps on the GSPTeck homepage.
FAQ
Does "client is offline" mean my Firestore data is gone?
No. It means the SDK couldn't reach the backend and didn't have that document cached, so it refused to guess. The document on the server is untouched; read it again once the connection to Firestore works.
Why does a query return empty offline instead of an error?
Firebase designed it that way: offline, a query with no cached documents returns an empty result, while a single-document get returns an error. Check snapshot.metadata.isFromCache before showing an empty state to the user.
Should I turn persistence off to fix the error?
Usually not. On Android and iOS, persistence is what lets a document get succeed offline. Turn it off only when testing against the emulator, where stale cached documents can mislead you.
Is Source.server a fix for stale data?
Only for reads that must be fresh. A server read skips the cache, so it throws whenever the backend can't be reached; wrap it in a try/catch and keep a fallback.
Sources
- Firebase: access data offline, persistence defaults and offline get behavior (checked 2026-12-01)
- Firebase: get data, source options (checked 2026-12-01)
- FlutterFire API: Source enum (server, cache, serverAndCache) (checked 2026-12-01)
- FlutterFire API: Settings class, web long-polling options (checked 2026-12-01)
- Firebase JS reference: FirestoreSettings, long-polling options (checked 2026-12-01)
- Firebase: connect your app to the Firestore emulator, 10.0.2.2 on Android (checked 2026-12-01)