flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.18k stars 26.64k forks source link

iOS: includeMetadataChanges does not recieve isFromCache false after first run #147501

Closed ramsayamarin closed 2 weeks ago

ramsayamarin commented 2 weeks ago

Steps to reproduce

Create a snapshot query like this example:

final query = templateQuery
          .startAt([geoHash])
          .endAt(['$geoHash~'])
          .limit(geoHashFetchCount)
          .snapshots(includeMetadataChanges: true)
          .listen(
            (snapshot) {
              if (snapshot.metadata.isFromCache) {
                return;
              }
             else...

Expected results

The docs say the following about includeMetadataChanges:

Whether the snapshot was created from cached data rather than guaranteed up-to-date server data. If you called DocumentReference. snapshots or Query. snapshots with includeMetadataChanges parameter set to true you will receive another snapshot with isFromCache equal to false once the client has received up-to-date data from the backend.

Actual results

On an Android device, this is true, and the snapshot is received twice, from the cache and then from server, but on iOS a cached followed by a server snapshot is only delivered the first time the query is executed, and if the same query is recreated later on the same data, a server snapshot is not received until the target data is updated. This was not the case in previous versions of the Firebase plugins or on Android, but it appeared in the latest version on iOS when I updated the plugins.

Code sample

Code sample ```dart final query = templateQuery .startAt([geoHash]) .endAt(['$geoHash~']) .limit(geoHashFetchCount) .snapshots(includeMetadataChanges: true) .listen( (snapshot) { if (snapshot.metadata.isFromCache) { return; } else... //This part is never reached if the query gets recreated on the same data, unless the data is updated ```

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs

Logs ```console [Paste your logs here] ```

Flutter Doctor output

Doctor output ```console [✓] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.22631.3527], locale en-US) [✓] Windows Version (Installed version of Windows is version 10 or higher) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc2) [✓] Chrome - develop for the web [✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.6.0) [✓] Android Studio (version 2022.2) [✓] IntelliJ IDEA Ultimate Edition (version 2024.1) [✓] Connected device (4 available) [✓] Network resources • No issues found! ```
danagbemava-nc commented 2 weeks ago

This appears to be an issue with cloud_firestore. This should be reported on the flutterfire repository.

Closing from here as this plugin is not maintained on this repo.

Thank you

github-actions[bot] commented 2 days ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.