title: Firebase RTDB: Call keepSynced while offline
body: <p>I'm working on a Flutter app that uses Firebase RTDB. I'm a bit unclear on the mechanism of <code>keepSynced()</code>:</p>
  <p>Our app creates new collections and adds data to these collections. The app also observes these collections to display the data. In the process, we call <code>keepSynced(true)</code> in order to keep the offline cache alive for these queries. Now we noticed that, when <em>creating a new collection</em> + calling <code>keepSynced(true)</code> <em>while offline</em>, the listener we register on the new collection doesn't receive data until the app goes online again. From then on, the caching and updating the listeners works as expected (online + offline).</p>
  <p>So, in code:</p>
  <pre><code>// Execute this while offline:
  
  // Enable permanent offline sync for a new node that doesn't exist yet on the Firebase server
  await database.ref().child('new_node').keepSynced(true);
  
  // Register listener
  database.ref().child('new_node').onValue.listen((event) =&gt; print(event));
  
  // Add data
  database.ref().child('new_node/child').set({'key': 'value'});
  </code></pre>
  <p>The listener will trigger only after the device goes online.</p>
  <p>The documentation on <code>keepSynced()</code> states</p>
  <blockquote>
  <p>By calling keepSynced(true) on a location, the data for that location will automatically be downloaded and kept in sync, even when no listeners are attached for that location. Additionally, while a location is kept synced, it will not be evicted from the persistent disk cache.</p>
  </blockquote>
  <p>So is it actually required to be connected with the Firebase backend (&quot;will automatically be downloaded&quot;) while calling <code>keepSynced()</code> in order for the offline caching/querying to work?</p>