flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [cloud_firestore] FirestoreListView not rebuilding with collection group queries

Open p4-k4 opened this issue 2 years ago • 3 comments

Bug report

Describe the bug FirestoreListView does not rebuild when using collection group queries.

Example

FirestoreListView(
            pageSize: 2,
            shrinkWrap: true,
            query: cloudFirestore
                .collectionGroup('connections')
                .where('uid', isEqualTo: 1),
            itemBuilder: (context, doc) => Column(
              children: [
                Text(doc.data().toString()),
                ElevatedButton(
                    onPressed: () async => doc.reference.delete(),
                    child: Text('Delete')),
              ],
            ),
          )

Expected behavior

Widget rebuilds when data is changed in cloud firestore.


Flutter doctor

Click To Expand
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79
    darwin-arm, locale en-NZ)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from:
      https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the
      Android SDK components.
      (or visit
      https://flutter.dev/docs/get-started/install/macos#andro
      id-setup for detailed instructions).
      If the Android SDK has been installed to a custom
      location, please use
      `flutter config --android-sdk` to update to that
      location.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] VS Code (version 1.70.1)
[✓] Connected device (3 available)

Flutter dependencies

Click To Expand
Dart SDK 2.17.6
Flutter SDK 3.0.5
sandbox 1.0.0+1

dependencies:
- cloud_firestore 3.4.7 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cloud_firestore_odm 1.0.0-dev.27 [cloud_firestore flutter json_annotation meta]
- draggable_scrollbar 0.1.0 [flutter]
- emojis 0.9.9 [collection]
- enum_to_string 2.0.1
- firebase_auth 3.8.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.21.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_database 9.1.4 [firebase_core firebase_core_platform_interface firebase_database_platform_interface firebase_database_web flutter]
- firebase_messaging 12.0.3 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_storage 10.3.6 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutterfire_ui 0.4.3+8 [cloud_firestore collection crypto desktop_webview_auth email_validator firebase_auth firebase_core firebase_database firebase_dynamic_links flutter flutter_facebook_auth flutter_localizations flutter_svg google_sign_in sign_in_with_apple twitter_login]
- freezed_annotation 2.1.0 [collection json_annotation meta]
- json_annotation 4.6.0 [meta]
- super_editor 0.2.2 [flutter attributed_text characters collection http linkify logging flutter_test super_text_layout uuid]

dev dependencies:
- build_runner 2.2.0 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- flutter_lints 2.0.1 [lints]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]
- freezed 2.1.0+1 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation]
- json_serializable 6.3.1 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]

transitive dependencies:
- _fe_analyzer_shared 47.0.0 [meta]
- analyzer 4.7.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- args 2.3.1
- async 2.8.2 [collection meta]
- attributed_text 0.2.0 [characters collection logging meta test]
- boolean_selector 2.1.0 [source_span string_scanner]
- build 2.3.0 [analyzer async convert crypto glob logging meta path]
- build_config 1.1.0 [checked_yaml json_annotation path pubspec_parse yaml]
- build_daemon 3.1.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.0.9 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml]
- build_runner_core 7.2.3 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml]
- built_collection 5.1.1
- built_value 8.4.1 [built_collection collection fixnum meta]
- characters 1.2.0
- charcode 1.3.1
- checked_yaml 2.0.1 [json_annotation source_span yaml]
- clock 1.1.0
- cloud_firestore_platform_interface 5.7.4 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 2.8.7 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- code_builder 4.2.0 [built_collection built_value collection matcher meta]
- collection 1.16.0
- convert 3.0.2 [typed_data]
- coverage 1.3.2 [args logging package_config path source_maps stack_trace vm_service]
- crypto 3.0.2 [typed_data]
- dart_style 2.2.3 [analyzer args path pub_semver source_span]
- desktop_webview_auth 0.0.9 [crypto flutter http]
- email_validator 2.1.17
- fake_async 1.3.0 [clock collection]
- file 6.1.4 [meta path]
- firebase_auth_platform_interface 6.7.0 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 4.4.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.5.1 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 1.7.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_database_platform_interface 0.2.2+4 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_database_web 0.2.1+6 [firebase_core firebase_core_web firebase_database_platform_interface flutter flutter_web_plugins js]
- firebase_dynamic_links 4.3.7 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface]
- firebase_dynamic_links_platform_interface 0.2.3+12 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 4.1.2 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.1.2 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_storage_platform_interface 4.1.14 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.3.4 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- fixnum 1.0.1
- flutter_facebook_auth 4.4.1 [flutter flutter_facebook_auth_platform_interface flutter_facebook_auth_web]
- flutter_facebook_auth_platform_interface 3.2.0 [flutter plugin_platform_interface]
- flutter_facebook_auth_web 3.2.0 [flutter flutter_web_plugins js flutter_facebook_auth_platform_interface]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_svg 1.1.4 [flutter meta path_drawing vector_math xml]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- frontend_server_client 2.1.3 [async path]
- glob 2.1.0 [async collection file path string_scanner]
- google_sign_in 5.4.1 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- google_sign_in_android 6.1.0 [flutter google_sign_in_platform_interface]
- google_sign_in_ios 5.5.0 [flutter google_sign_in_platform_interface]
- google_sign_in_platform_interface 2.3.0 [flutter plugin_platform_interface quiver]
- google_sign_in_web 0.10.2 [flutter flutter_web_plugins google_sign_in_platform_interface js]
- graphs 2.1.0 [collection]
- http 0.13.5 [async http_parser meta path]
- http_multi_server 3.2.1 [async]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- intl 0.17.0 [clock path]
- io 1.0.3 [meta path string_scanner]
- js 0.6.4
- linkify 4.1.0
- lints 2.0.0
- logging 1.0.2
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.4
- meta 1.7.0
- mime 1.0.2
- node_preamble 2.0.1
- package_config 2.1.0 [path]
- path 1.8.1
- path_drawing 1.0.1 [vector_math meta path_parsing flutter]
- path_parsing 1.0.1 [vector_math meta]
- petitparser 5.0.0 [meta]
- plugin_platform_interface 2.1.2 [meta]
- pool 1.5.1 [async stack_trace]
- pub_semver 2.1.1 [collection meta]
- pubspec_parse 1.2.1 [checked_yaml collection json_annotation pub_semver yaml]
- quiver 3.1.0 [matcher]
- shelf 1.3.2 [async collection http_parser path stack_trace stream_channel]
- shelf_packages_handler 3.0.1 [path shelf shelf_static]
- shelf_static 1.1.1 [convert http_parser mime path shelf]
- shelf_web_socket 1.0.2 [shelf stream_channel web_socket_channel]
- sign_in_with_apple 3.3.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web]
- sign_in_with_apple_platform_interface 1.0.0 [flutter plugin_platform_interface meta]
- sign_in_with_apple_web 1.0.1 [flutter flutter_web_plugins sign_in_with_apple_platform_interface js]
- sky_engine 0.0.99
- source_gen 1.2.2 [analyzer async build dart_style glob meta path source_span yaml]
- source_helper 1.3.2 [analyzer collection source_gen]
- source_map_stack_trace 2.1.0 [path stack_trace source_maps]
- source_maps 0.10.10 [source_span]
- source_span 1.8.2 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- super_text_layout 0.1.3 [flutter attributed_text logging]
- term_glyph 1.2.0
- test 1.21.1 [analyzer async boolean_selector collection coverage http_multi_server io js node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel typed_data web_socket_channel webkit_inspection_protocol yaml test_api test_core]
- test_api 0.4.9 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- test_core 0.4.13 [analyzer async args boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api]
- timing 1.0.0 [json_annotation]
- twitter_login 4.2.3 [flutter crypto http]
- typed_data 1.3.1 [collection]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2
- vm_service 8.3.0
- watcher 1.0.1 [async path]
- web_socket_channel 2.2.0 [async crypto stream_channel]
- webkit_inspection_protocol 1.2.0 [logging]
- xml 6.1.0 [collection meta petitparser]
- yaml 3.1.1 [collection source_span string_scanner]

p4-k4 avatar Sep 13 '22 09:09 p4-k4

Thanks for the report @flutterfocus

.where('uid', isEqualTo: 1),

Does it work if you use orderBy, for name field for example ?

Can you also confirm if you have setup the indexes for the query you are using in console ?

darshankawar avatar Sep 13 '22 10:09 darshankawar

Thanks for the report @flutterfocus

.where('uid', isEqualTo: 1),

Does it work if you use orderBy, for name field for example ?

Can you also confirm if you have setup the indexes for the query you are using in console ?

@darshankawar Hi there, yes indexes were created and the results are correctly returned when using .where('uid', isEqualTo: 1) however, the widget does not rebuild when a change is made on the "connections" sub collection. Hot restart (forcing a rebuild) will update the widget correctly.

Here are the indexes. Screen Shot 2022-09-14 at 8 06 17 AM

Using .where('uid', isEqualTo: 1).orderBy('name') returns no results, also without errors.

This is the structure I've got for testing this. Screen Shot 2022-09-14 at 8 07 04 AM

Cheers

p4-k4 avatar Sep 13 '22 20:09 p4-k4

Thanks for the update. Using the code sample provided and using it in plugin's example, running it on iOS simulator, I am getting same behavior as reported.

This is related to FirestoreListView from flutterfire_ui plugin, so labeling accordingly and to get further insights from the team on the expected behavior in this use case.

darshankawar avatar Sep 14 '22 10:09 darshankawar

@p4-k4 you're using wrong collection id in your index. In your case, collection id should be connections instead of users. I verified that collectionGroup queries work as expected with FirestoreListView with correct indices built.

lesnitsky avatar Dec 09 '22 12:12 lesnitsky