firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.6k stars 3.95k forks source link

πŸ› [cloud_firestore] snapshot is not giving realtime updates with where clause #7794

Closed sohaibnoman closed 2 years ago

sohaibnoman commented 2 years ago

Bug report

Describe the bug Cloud Firestore snapshot is not updating the changes made, when queried with where(x, arrayContains: y)

Steps to reproduce

Steps to reproduce the behavior:

This is the code I used to setup the stream

return _firestore
        .collection(channelCollection)
        .doc(chatChannel)
        .collection(topicCollection)
        .where('members', arrayContains: uid)
        .orderBy('time', descending: true)
        .limit(pageSize)
        .snapshots()
        .map(
      (list) {
        if (list.docs.isNotEmpty) {
          _lastChat = list.docs.last;
        }
        return list.docs
            .map((document) => Chat.fromFirestore(document))
            .toList();
      },
    );

When making changes to the documents returned from the query, no updated snapshot return. If i comment out the where clause everything works as expected

Expected behavior

I expected the query to work similarly with or with out the where clause

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [βœ“] Flutter (Channel stable, 2.8.1, on macOS 11.4 20F71 darwin-x64, locale en) [βœ“] Android toolchain - develop for Android devices (Android SDK version 32.0.0) [βœ“] Xcode - develop for iOS and macOS (Xcode 13.1) [βœ“] Chrome - develop for the web [βœ“] Android Studio (version 2020.3) [βœ“] VS Code (version 1.63.2) [βœ“] Connected device (1 available) β€’ No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 2.15.1 Flutter SDK 2.8.1 campus 1.0.0+1 dependencies: - animations 2.0.2 [flutter] - cloud_firestore 3.1.0 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_functions 3.2.4 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - connectivity 3.0.6 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web] - cupertino_icons 1.0.4 - firebase_auth 3.2.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 1.10.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_storage 10.2.3 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_iconpicker 3.1.0 [flutter cupertino_icons font_awesome_flutter] - flutter_spinkit 5.1.0 [flutter] - flutter_svg 0.23.0+1 [flutter meta path_drawing vector_math xml] - font_awesome_flutter 9.2.0 [flutter] - google_fonts 2.1.0 [flutter http path_provider crypto] - image_cropper 1.4.1 [flutter] - image_picker 0.8.4+4 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface] - intl 0.17.0 [clock path] - provider 6.0.1 [collection flutter nested] - tuple 2.0.0 [quiver] - url_launcher 6.0.17 [flutter meta url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - uuid 3.0.5 [crypto] dev dependencies: - flutter_lints 1.0.4 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] transitive dependencies: - async 2.8.2 [collection meta] - boolean_selector 2.1.0 [source_span string_scanner] - characters 1.2.0 - charcode 1.3.1 - clock 1.1.0 - cloud_firestore_platform_interface 5.4.5 [collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 2.5.0 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.0.19 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.2.5 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.15.0 - connectivity_for_web 0.4.0+1 [connectivity_platform_interface flutter_web_plugins flutter] - connectivity_macos 0.2.1+2 [flutter connectivity_platform_interface] - connectivity_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - cross_file 0.3.2 [flutter js meta] - crypto 3.0.1 [collection typed_data] - fake_async 1.2.0 [clock collection] - ffi 1.1.2 - file 6.1.2 [meta path] - firebase_auth_platform_interface 6.1.4 [firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 3.2.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.2.3 [collection flutter meta plugin_platform_interface] - firebase_core_web 1.5.3 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_storage_platform_interface 4.0.10 [collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.2.4 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_plugin_android_lifecycle 2.0.5 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math] - http 0.13.4 [async http_parser meta path] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - image_picker_for_web 2.1.4 [flutter flutter_web_plugins image_picker_platform_interface meta] - image_picker_platform_interface 2.4.1 [flutter http meta plugin_platform_interface cross_file] - js 0.6.3 - lints 1.0.1 - matcher 0.12.11 [stack_trace] - meta 1.7.0 - nested 1.0.0 [flutter] - path 1.8.0 - path_drawing 0.5.1+1 [vector_math meta path_parsing flutter] - path_parsing 0.2.1 [vector_math meta] - path_provider 2.0.7 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - path_provider_android 2.0.9 [flutter path_provider_platform_interface] - path_provider_ios 2.0.7 [flutter path_provider_platform_interface] - path_provider_linux 2.1.2 [flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.3 [flutter] - path_provider_platform_interface 2.0.0 [flutter meta platform plugin_platform_interface] - path_provider_windows 2.0.4 [ffi flutter meta path path_provider_platform_interface win32] - pedantic 1.11.1 - petitparser 4.4.0 [meta] - platform 3.0.2 - plugin_platform_interface 2.0.2 [meta] - process 4.2.4 [file path platform] - quiver 3.0.1+1 [matcher] - rxdart 0.27.3 - sky_engine 0.0.99 - source_span 1.8.1 [collection path term_glyph] - sqflite 2.0.1 [flutter sqflite_common path] - sqflite_common 2.1.0 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - string_scanner 1.1.0 [charcode source_span] - synchronized 3.0.0 - term_glyph 1.2.0 - test_api 0.4.3 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.0 [collection] - url_launcher_android 6.0.13 [flutter meta url_launcher_platform_interface] - url_launcher_ios 6.0.13 [flutter meta url_launcher_platform_interface] - url_launcher_linux 2.0.2 [flutter] - url_launcher_macos 2.0.2 [flutter] - url_launcher_platform_interface 2.0.4 [flutter plugin_platform_interface] - url_launcher_web 2.0.5 [flutter flutter_web_plugins meta url_launcher_platform_interface] - url_launcher_windows 2.0.2 [flutter] - vector_math 2.1.1 - win32 2.3.1 [ffi] - xdg_directories 0.2.0 [meta path process] - xml 5.3.1 [collection meta petitparser] ```

darshankawar commented 2 years ago

.where('members'

@sohaibnoman Does it work with any other field or it same with all fields ?

sohaibnoman commented 2 years ago

@darshankawar Hi sorry for the late answers, so after trying it for other fields like

.where('memberA.admin', isEqualTo: true) or .where('seenby', arrayContains: uid)

Instead of the 'members' field it still does not work, which is strange as when I remove the where clause it do work

darshankawar commented 2 years ago

Thanks for the update. I see the same behavior using plugin's example and on latest plugin version.

cloud_firestore: ^3.1.6

sohaibnoman commented 2 years ago

I debugged my solution with an Android device and it turns out, I was just missing the index for the where clause in the firebase console.