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.71k stars 3.97k forks source link

🐛 [cloud_firestore][web] Use of Filter.Or in the query makes the other params useless on web #11714

Closed Samuele1no closed 12 months ago

Samuele1no commented 1 year ago

Bug report Describe the bug
 Executing a query using “Filter.Or”, the other condition are no longer considered on web platform. The same code on iOS and Android is not subject to this problem and the query returns the data correctly.

Steps to reproduce Steps to reproduce the behaviour:

  1. Perform a query using Filter.Or and with other .where conditions on web.

 query example:
 instance.collection('...')         .where(Filter.or(           Filter("category", isEqualTo: categoryId),           Filter("ex_category", arrayContains: categoryId),         ))         .where('is_active', isEqualTo: true);

3.Analyse the results and the .where condition are no considered.

Flutter doctor Run flutter doctor and paste the output below:

Click To Expand ``` [✓] Flutter (Channel stable, 3.10.4, on macOS 13.5.2 22G91 darwin-arm64, locale en-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.2) [✓] VS Code (version 1.83.0) [✓] Connected device (2 available) [✓] Network resources • No issues found! ```

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

Click To Expand ``` dependencies: - auto_size_text 3.0.0 [flutter] - cached_network_image 3.2.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - cloud_firestore 4.9.3 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_functions 4.0.12 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - connectivity_wrapper 1.0.6 [flutter provider] - crypto 3.0.2 [typed_data] - cupertino_icons 1.0.2 - easy_localization 3.0.2 [flutter shared_preferences intl args path easy_logger flutter_localizations] - encrypt 5.0.1 [args asn1lib clock collection crypto pointycastle] - enum_to_string 2.0.1 - equatable 2.0.3 [collection meta] - file 6.1.4 [meta path] - firebase_analytics 10.1.5 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 4.9.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.17.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 3.0.16 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_dynamic_links 5.0.16 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface] - firebase_messaging 14.2.6 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine] - flutter_geo_hash 0.0.4 [flutter] - flutter_hooks 0.18.4 [flutter] - flutter_inappwebview 6.0.0-beta.22 [flutter flutter_web_plugins js flutter_inappwebview_internal_annotations] - flutter_keyboard_visibility 5.2.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter] - flutter_local_notifications 14.0.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math] - flutter_offline 2.1.0 [flutter connectivity_plus network_info_plus] - flutter_picker 2.0.3 [flutter] - flutter_secure_storage 8.0.0 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta] - flutter_slidable 0.6.0 [flutter] - flutter_spinkit 5.1.0 [flutter] - flutter_stripe 8.0.0+1 [flutter stripe_android stripe_ios stripe_platform_interface] - flutter_stripe_web 3.0.0 [flutter flutter_web_plugins freezed_annotation stripe_platform_interface js stripe_js] - flutter_svg 2.0.3 [flutter vector_graphics vector_graphics_codec vector_graphics_compiler] - geocoding 2.0.4 [flutter geocoding_platform_interface] - geoflutterfire2 2.3.15 [flutter cloud_firestore rxdart] - geolocator 9.0.2 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows] - google_maps_flutter 2.1.3 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface] - google_sign_in 6.1.0 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web] - hooks_riverpod 2.3.3 [collection flutter flutter_hooks flutter_riverpod riverpod state_notifier] - http 0.13.6 [async http_parser meta] - internet_connection_checker 0.0.1+3 - intl 0.18.0 [clock meta path] - loading_overlay 0.3.0 [flutter] - logger 1.1.0 - maps_launcher 2.0.1 [flutter flutter_web_plugins url_launcher] - material_design_icons_flutter 5.0.6595 [flutter] - mobile_scanner 3.2.0 [flutter flutter_web_plugins js] - mockito 5.4.0 [analyzer build code_builder collection dart_style matcher meta path source_gen test_api] - modal_bottom_sheet 3.0.0-pre [flutter] - ntp 2.0.0 - numberpicker 2.1.1 [flutter infinite_listview] - package_info_plus 3.1.0 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - path_provider 2.0.10 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - permission_handler 10.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - platform_info 3.1.0 [meta] - riverpod 2.3.3 [meta stack_trace state_notifier] - salomon_bottom_bar 3.3.1 [flutter] - shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - sign_in_with_apple 4.3.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web] - timezone 0.9.0 [path] - uni_links 0.5.1 [flutter uni_links_platform_interface uni_links_web] - universal_html 2.0.8 [async csslib charcode collection html meta source_span typed_data universal_io] - url_launcher 6.1.2 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - url_strategy 0.2.0 [flutter_web_plugins] - uuid 3.0.6 [crypto] - vies 1.0.2 [html_unescape http] dev dependencies: - build_runner 2.4.1 [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_launcher_icons 0.13.1 [args checked_yaml cli_util image json_annotation path yaml] - flutter_lints 1.0.4 [lints] - flutter_native_splash 2.3.2 [args flutter flutter_web_plugins js html image meta path universal_io xml yaml] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - test 1.24.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 matcher] transitive dependencies: - _fe_analyzer_shared 61.0.0 [meta] - _flutterfire_internals 1.3.7 [collection firebase_core firebase_core_platform_interface flutter meta] - analyzer 5.13.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - archive 3.1.11 [crypto path] - args 2.4.2 - asn1lib 1.4.1 - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - build 2.3.1 [analyzer async convert crypto glob logging meta path] - build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 4.0.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.2.0 [analyzer async build collection crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.2.7 [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.4 [built_collection collection fixnum meta] - cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.3.0 - charcode 1.3.1 - checked_yaml 2.0.2 [json_annotation source_span yaml] - cli_util 0.4.0 [meta path] - clock 1.1.1 - cloud_firestore_platform_interface 5.16.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.7.2 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.4.2 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.5.2 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - code_builder 4.4.0 [built_collection built_value collection matcher meta] - collection 1.17.1 - connectivity_plus 2.2.0 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows] - connectivity_plus_linux 1.3.1 [flutter connectivity_plus_platform_interface meta nm] - connectivity_plus_macos 1.2.1 [connectivity_plus_platform_interface flutter] - connectivity_plus_platform_interface 1.2.0 [flutter meta plugin_platform_interface] - connectivity_plus_web 1.2.0 [connectivity_plus_platform_interface flutter_web_plugins flutter] - connectivity_plus_windows 1.2.0 [connectivity_plus_platform_interface flutter] - convert 3.1.1 [typed_data] - coverage 1.6.3 [args logging package_config path source_maps stack_trace vm_service] - csslib 0.17.1 [source_span] - dart_style 2.2.4 [analyzer args path pub_semver source_span] - dbus 0.7.8 [args ffi meta xml] - easy_logger 0.0.2 [flutter] - fake_async 1.3.1 [clock collection] - ffi 2.0.2 - firebase_analytics_platform_interface 3.6.2 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.4+2 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth_platform_interface 6.18.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.8.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta] - firebase_core_platform_interface 4.8.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.8.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.6.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_dynamic_links_platform_interface 0.2.6+2 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 4.5.2 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.5.2 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - fixnum 1.0.1 - flutter_blurhash 0.6.0 [flutter meta pedantic] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_inappwebview_internal_annotations 1.1.0 - flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface] - flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter] - flutter_local_notifications_linux 4.0.0+1 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories] - flutter_local_notifications_platform_interface 7.0.0+1 [flutter plugin_platform_interface] - flutter_plugin_android_lifecycle 2.0.15 [flutter] - flutter_riverpod 2.3.3 [collection flutter meta riverpod state_notifier] - flutter_secure_storage_linux 1.2.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 3.0.1 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.2 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.1.2 [flutter flutter_secure_storage_platform_interface flutter_web_plugins js] - flutter_secure_storage_windows 2.1.1 [flutter flutter_secure_storage_platform_interface] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - freezed_annotation 2.2.0 [collection json_annotation meta] - frontend_server_client 3.2.0 [async path] - geocoding_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - geolocator_android 4.1.8 [flutter geolocator_platform_interface] - geolocator_apple 2.1.2 [flutter geolocator_platform_interface] - geolocator_platform_interface 4.0.4 [flutter plugin_platform_interface vector_math meta] - geolocator_web 2.1.4 [flutter flutter_web_plugins geolocator_platform_interface] - geolocator_windows 0.1.0 [flutter geolocator_platform_interface] - glob 2.1.0 [async collection file path string_scanner] - google_identity_services_web 0.2.1 [js meta] - google_maps_flutter_platform_interface 2.2.7 [collection flutter plugin_platform_interface stream_transform] - google_sign_in_android 6.1.14 [flutter google_sign_in_platform_interface] - google_sign_in_ios 5.6.2 [flutter google_sign_in_platform_interface] - google_sign_in_platform_interface 2.4.1 [flutter plugin_platform_interface quiver] - google_sign_in_web 0.12.0+1 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http js] - graphs 2.3.1 [collection] - html 0.15.4 [csslib source_span] - html_unescape 2.0.0 - http_multi_server 3.2.1 [async] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - image 4.0.17 [archive meta xml] - infinite_listview 1.1.0 [flutter] - io 1.0.4 [meta path string_scanner] - js 0.6.7 [meta] - json_annotation 4.8.1 [meta] - lints 1.0.1 - logging 1.1.1 - matcher 0.12.15 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.2.0 - meta 1.9.1 - mime 1.0.4 - nested 1.0.0 [flutter] - network_info_plus 2.1.2 [flutter meta network_info_plus_platform_interface network_info_plus_linux network_info_plus_macos network_info_plus_windows network_info_plus_web] - network_info_plus_linux 1.1.2 [collection flutter meta network_info_plus_platform_interface nm] - network_info_plus_macos 1.3.0 [network_info_plus_platform_interface flutter] - network_info_plus_platform_interface 1.1.1 [flutter meta plugin_platform_interface] - network_info_plus_web 1.0.1 [flutter flutter_web_plugins network_info_plus_platform_interface] - network_info_plus_windows 1.0.2 [flutter network_info_plus_platform_interface] - nm 0.5.0 [dbus] - node_preamble 2.0.2 - octo_image 1.0.1 [flutter flutter_blurhash] - package_config 2.1.0 [path] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.3 - path_parsing 1.0.1 [vector_math meta] - path_provider_android 2.0.11 [flutter path_provider_platform_interface] - path_provider_ios 2.0.7 [flutter path_provider_platform_interface] - path_provider_linux 2.1.11 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.5 [flutter path_provider_platform_interface] - path_provider_platform_interface 2.0.3 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.6 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - permission_handler_android 10.2.2 [flutter permission_handler_platform_interface] - permission_handler_apple 9.0.8 [flutter permission_handler_platform_interface] - permission_handler_platform_interface 3.9.0 [flutter meta plugin_platform_interface] - permission_handler_windows 0.1.2 [flutter permission_handler_platform_interface] - petitparser 5.4.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.5 [meta] - pointycastle 3.7.3 [collection convert js] - pool 1.5.1 [async stack_trace] - process 4.2.4 [file path platform] - provider 5.0.0 [collection flutter nested] - pub_semver 2.1.3 [collection meta] - pubspec_parse 1.2.3 [checked_yaml collection json_annotation pub_semver yaml] - quiver 3.2.1 [matcher] - rxdart 0.27.7 - shared_preferences_android 2.0.10 [flutter shared_preferences_platform_interface] - shared_preferences_ios 2.0.9 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.0.4 [file flutter path path_provider_linux shared_preferences_platform_interface] - shared_preferences_macos 2.0.2 [flutter shared_preferences_platform_interface] - shared_preferences_platform_interface 2.0.0 [flutter] - shared_preferences_web 2.0.3 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.0.4 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - shelf 1.4.0 [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.3 [shelf stream_channel web_socket_channel] - 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.6 [analyzer async build dart_style glob meta path source_span yaml] - source_map_stack_trace 2.1.1 [path source_maps stack_trace] - source_maps 0.10.12 [source_span] - source_span 1.9.1 [collection path term_glyph] - sqflite 2.0.2 [flutter sqflite_common path] - sqflite_common 2.2.0 [synchronized path meta] - stack_trace 1.11.0 [path] - state_notifier 0.7.2+1 [meta] - stream_channel 2.1.1 [async] - stream_transform 2.1.0 - string_scanner 1.2.0 [source_span] - stripe_android 8.0.0+1 [flutter] - stripe_ios 8.0.0 [flutter] - stripe_js 2.0.1 [freezed_annotation js] - stripe_platform_interface 8.0.0 [flutter freezed_annotation json_annotation meta plugin_platform_interface] - synchronized 3.0.0 - term_glyph 1.2.1 - test_api 0.5.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - test_core 0.5.1 [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.1 [json_annotation] - typed_data 1.3.0 [collection] - uni_links_platform_interface 1.0.0 [flutter plugin_platform_interface] - uni_links_web 0.1.0 [flutter flutter_web_plugins uni_links_platform_interface] - universal_io 2.2.2 [collection meta typed_data] - url_launcher_android 6.0.14 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.14 [flutter url_launcher_platform_interface] - url_launcher_linux 2.0.3 [flutter] - url_launcher_macos 2.0.3 [flutter] - url_launcher_platform_interface 2.0.5 [flutter plugin_platform_interface] - url_launcher_web 2.0.8 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 2.0.2 [flutter] - vector_graphics 1.1.6 [flutter vector_graphics_codec] - vector_graphics_codec 1.1.6 - vector_graphics_compiler 1.1.6 [args meta path_parsing xml vector_graphics_codec] - vector_math 2.1.4 - vm_service 9.4.0 - watcher 1.0.2 [async path] - web_socket_channel 2.3.0 [async crypto stream_channel] - webkit_inspection_protocol 1.2.0 [logging] - win32 4.1.4 [ffi] - xdg_directories 0.2.0+1 [meta path process] - xml 6.3.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```

darshankawar commented 1 year ago

@Samuele1no Can you provide complete reproducible code sample along with results on mobile and web that shows the difference ?

google-oss-bot commented 1 year ago

Hey @Samuele1no. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

Samuele1no commented 1 year ago

@darshankawar Sorry for the delay, I made a little project on my repo: https://github.com/Samuele1no/cloud_firestore_query_error

If you run this on iOS and web at the same time you will see the problem.

Thank you

darshankawar commented 1 year ago

Thanks for the update and providing a repro @Samuele1no Can you also please provide firestore db structure in firebase console so that I can try to re-create it at my end and then run the code to verify the reported behavior ?

Also, are you using latest version of plugin ? There was a recent fix made to the plugin related to Filtering queries so make sure you are on latest version of plugin.

Also, check if this documentation on Filtering queries help to know as why it may be giving you different results.

Samuele1no commented 1 year ago

The demo project dependecy are: firebase_core: ^2.20.0 and cloud_firestore: ^4.12.0

So yes they were the latest yesterday, now is available also the cloud_firestore: 4.12.1 but only from 20 hours. Talking about the db structure i have only one collection called "class1" and inside it 4 object. Here the response of "QuerySnapshot snapshot = await firestore.collection('class1').get();"

{name: tom, isPresent: true, isAvailable: true}
{name: philip, isPresent: true, isAvailable: false}
{name: Mich, isPresent: false, isAvailable: true}
{name: jack, isPresent: false, isAvailable: false}

And the problem is present after this query:

QuerySnapshot snapshot = await firestore
        .collection('class1')
        .where(Filter.or(
          Filter("name", isEqualTo: "Mich"),
          Filter("name", isEqualTo: "tom"),
        ))
        .where("isAvailable", isEqualTo: false)
        .get();

Thanks

darshankawar commented 1 year ago

Thanks for the update @Samuele1no Upon running the code sample, I get below on mobile (Android) and web respectively:

  1. Mobile:
Screenshot 2023-10-30 at 5 13 36 PM
  1. Web:
Screenshot 2023-10-30 at 5 14 34 PM

Is this a correct / expected behavior ?

Samuele1no commented 1 year ago

@darshankawar how you can see in the bottom part of the page, the same query gives different response based on the platform. So the result is what expected to show the bug.

darshankawar commented 1 year ago

Thanks for the update. Based on my findings, keeping this issue open and labeling for tracking.

runnable code sample ``` import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; import 'firebase_options.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); runApp(const MaterialApp( home: MyApp(), )); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("Title"), ), body: const Column(children: [ SizedBox( height: 10, ), Text( "GetAll", ), ShowAllDb(), Divider( height: 10, color: Colors.black, ), SizedBox( height: 10, ), Text( "Fetching with query", ), FetchingWidget() ]), ); } } class ShowAllDb extends StatefulWidget { const ShowAllDb({super.key}); @override State createState() => _ShowAllDbState(); } class _ShowAllDbState extends State { Future> _getAll() async { FirebaseFirestore firestore = FirebaseFirestore.instance; QuerySnapshot snapshot = await firestore.collection('class1').get(); // Convert the QuerySnapshot to a List List users = []; for (QueryDocumentSnapshot doc in snapshot.docs) { User user = User.fromSnapshot(doc); users.add(user); } return users; } @override Widget build(BuildContext context) { return FutureBuilder>( future: _getAll(), builder: (context, snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: return const Center(child: CircularProgressIndicator()); case ConnectionState.done: if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } else { List users = snapshot.data ?? []; return ListView.separated( shrinkWrap: true, itemCount: users.length, separatorBuilder: (context, index) => const Divider(), itemBuilder: (context, index) => ListTile( title: Text(users[index].toString()), ), ); } default: return const Text('Unhandled state'); } }, ); } } class FetchingWidget extends StatefulWidget { const FetchingWidget({super.key}); @override State createState() => _FetchingWidgetState(); } class _FetchingWidgetState extends State { Future> _future() async { FirebaseFirestore firestore = FirebaseFirestore.instance; QuerySnapshot snapshot = await firestore .collection('class1') .where(Filter.or( Filter("name", isEqualTo: "Mich"), Filter("name", isEqualTo: "tom"), )) .where("isAvailable", isEqualTo: false) .get(); // Convert the QuerySnapshot to a List List users = []; for (QueryDocumentSnapshot doc in snapshot.docs) { User user = User.fromSnapshot(doc); users.add(user); } return users; } @override Widget build(BuildContext context) { return FutureBuilder>( future: _future(), builder: (context, snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: return const Center(child: CircularProgressIndicator()); case ConnectionState.done: if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } else { List users = snapshot.data ?? []; return ListView.separated( shrinkWrap: true, itemCount: users.length, separatorBuilder: (context, index) => const Divider(), itemBuilder: (context, index) => ListTile( title: Text(users[index].toString()), ), ); } default: return const Text('Unhandled state'); } }, ); } } /* ///USER MAP EXAMPLE Map document = { 'name': 'Mich', 'isPresent': false, 'isAvailable': true }; */ class User { String name; bool isPresent; bool isAvailable; User( {required this.name, required this.isPresent, required this.isAvailable}); factory User.fromJson(Map json) { return User( name: json['name'], isPresent: json['isPresent'], isAvailable: json['isAvailable'], ); } Map toJson() { return { 'name': name, 'isPresent': isPresent, 'isAvailable': isAvailable, }; } factory User.fromSnapshot(QueryDocumentSnapshot doc) { return User( name: doc.get('name'), isPresent: doc.get('isPresent'), isAvailable: doc.get('isAvailable'), ); } @override String toString() { return 'User(name: $name, isPresent: $isPresent, isAvailable: $isAvailable)'; } } ```
blaneyneil commented 12 months ago

I can confirm this is breaking on web. i'm building a query like so:

Query _query = someCollection.where('someId', isEqualTo: ID);

if (some condition) {
   _query = _query.where(Filter.or(
      Filter('someList', isEqualTo: ['a]), 
      Filter('someList', isEqualTo: ['b']),
    ));
}

return _query.snapshots();

it works as expected on iOS and Android. on the web, everything works as you'd expect if the "some condition" is not met. however, if the Filter.or is triggered on the web then the entire stream breaks with a permissions error:

FirebaseError: [code=permission-denied]: Missing or insufficient permissions.

and it looks like the original where('someId', isEqualTo: ID) condition is subsequently being ignored.

firebase_core: ^2.22.0 cloud_firestore: ^4.13.0

blaneyneil commented 12 months ago

For those in need of a solution for the web in the meantime, you can't mix and match where clauses with Filter.or clauses. if you need to use a Filter.or then you have to convert your where into Filter.and clauses.

So this will work:

_query.where(Filter.and(
      Filter('someId', isEqualTo: ID),

      Filter.or(
        Filter('someList', isEqualTo: ['a]), 
        Filter('someList', isEqualTo: ['b']),
      ),
    ));

but this will not:

_query
      .where('someId', isEqualTo: ID)

      .where(Filter.or(
        Filter('someList', isEqualTo: ['a]), 
        Filter('someList', isEqualTo: ['b']),
      )),
    );