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.62k stars 3.95k forks source link

πŸ› cloud_firestore DocumentSnapshot throws an error when a field is not available #10067

Closed SpiegelSoft closed 1 year ago

SpiegelSoft commented 1 year ago

Bug report

Describe the bug This is inconsistent with other Firestore implementations. It makes it very difficult to handle the case when a new field is added to a collection, and the developer wants to fall back to a legacy implementation if the field is not present in the data record.

Steps to reproduce

  1. Access a document snapshot.
  2. Attempt to access a field "x" of type X that is not present in the accessed document.
  3. Attempt to determine whether or not the field "x" is present in the document, without using data() to wastefully evaluate every single field.

Expected behavior

I would expect that `doc['x']' would return an object of type X?, consistent with the implementation of the Dart Map type and the Node and Angular implementations of Firestore.

Instead, an error is thrown, which is the wrong behaviour in my view, and does not fit the use case described above.

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [βœ“] Flutter (Channel stable, 3.3.9, on macOS 12.6 21G115 darwin-arm, locale en-GB) [βœ“] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [βœ“] Xcode - develop for iOS and macOS (Xcode 14.1) [βœ“] Android Studio (version 2021.2) [βœ“] VS Code (version 1.73.1) [βœ“] Connected device (3 available) [βœ“] HTTP Host Availability β€’ No issues found! ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 2.18.5 Flutter SDK 3.3.9 safe 2.2.15+575 dependencies: - another_flushbar 1.12.29 [flutter] - auto_size_text 3.0.0 [flutter] - background_fetch 1.1.2 [flutter] - badges 2.0.3 [flutter] - battery_plus 3.0.2 [flutter flutter_web_plugins battery_plus_platform_interface meta upower] - cloud_firestore 4.0.3 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_functions 4.0.3 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - connectivity_plus 3.0.2 [flutter flutter_web_plugins connectivity_plus_platform_interface js meta nm] - country_code_picker 2.0.2 [flutter modal_bottom_sheet collection universal_platform] - country_icons 2.0.2 [flutter] - cupertino_icons 1.0.5 - dartx 1.1.0 [characters collection crypto meta path time] - date_format 2.0.7 - device_info 2.0.3 [flutter device_info_platform_interface] - device_simulator 0.9.6 [flutter custom_navigator] - devicelocale 0.5.5 [flutter flutter_web_plugins] - easy_localization 3.0.1 [flutter shared_preferences intl args path easy_logger flutter_localizations] - email_validator 2.1.17 - firebase_analytics 10.0.3 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 4.1.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.1.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 3.0.3 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_dynamic_links 5.0.3 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface] - firebase_messaging 14.0.3 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_appauth 4.2.1 [flutter flutter_appauth_platform_interface] - flutter_background_geolocation 4.8.3 [flutter collection background_fetch] - flutter_keyboard_visibility 5.4.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_linux flutter_keyboard_visibility_macos flutter_keyboard_visibility_web flutter_keyboard_visibility_windows flutter] - flutter_libphonenumber 1.2.4 [flutter] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math] - flutter_secure_storage 6.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 2.0.0 [flutter] - flutter_spinkit 5.1.0 [flutter] - flutter_svg 1.1.6 [flutter meta path_drawing vector_math xml] - flutter_touch_spin 2.0.0 [flutter intl] - get_it 7.2.0 [async collection] - google_maps_flutter 2.2.1 [flutter google_maps_flutter_android google_maps_flutter_ios google_maps_flutter_platform_interface] - hive 2.2.3 [meta crypto] - hive_flutter 1.1.0 [flutter hive path_provider path] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - intl 0.17.0 [clock path] - package_info_plus 3.0.1 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - page_transition 2.0.9 [flutter] - pedantic 1.11.1 - percent_indicator 4.2.2 [flutter] - permission_handler 10.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - petitparser 5.1.0 [meta] - pin_code_fields 7.4.0 [flutter] - provider 6.0.4 [collection flutter nested] - quiver 3.1.0 [matcher] - retry 3.1.0 - rflutter_alert 2.0.4 [flutter] - rxdart 0.27.5 - 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] - sms_autofill 2.2.0 [pin_input_text_field flutter] - solid_bottom_sheet 0.1.10 [flutter] - synchronized 3.0.0+3 - timeago 3.3.0 [intl] - timezone 0.9.0 [path] - tuple 2.0.1 - uni_links 0.5.1 [flutter uni_links_platform_interface uni_links_web] - url_launcher 6.1.6 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] dev dependencies: - analyzer 5.2.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - build_resolvers 2.1.0 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner 2.3.2 [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_driver 0.0.0 [file flutter flutter_test fuchsia_remote_debug_protocol path meta vm_service webdriver archive async boolean_selector characters clock collection crypto matcher material_color_utilities platform process source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api typed_data vector_math] - flutter_launcher_icons 0.10.0 [args checked_yaml cli_util image json_annotation path yaml] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - hive_generator 2.0.0 [build source_gen hive analyzer source_helper] - integration_test 0.0.0 [flutter flutter_driver flutter_test path vm_service archive async boolean_selector characters clock collection crypto fake_async file matcher material_color_utilities meta source_span stack_trace stream_channel string_scanner sync_http term_glyph test_api typed_data vector_math webdriver] - mockito 5.3.2 [analyzer build code_builder collection dart_style matcher meta path source_gen test_api] - test 1.21.7 [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] dependency overrides: - test_api 0.4.15 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] transitive dependencies: - _fe_analyzer_shared 50.0.0 [meta] - _flutterfire_internals 1.0.6 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - archive 3.3.0 [crypto path] - args 2.3.1 - async 2.9.0 [collection meta] - battery_plus_platform_interface 1.2.2 [flutter meta plugin_platform_interface] - boolean_selector 2.1.0 [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 3.1.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - 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.2 [built_collection collection fixnum meta] - characters 1.2.1 - checked_yaml 2.0.1 [json_annotation source_span yaml] - cli_util 0.3.5 [meta path] - clock 1.1.1 - cloud_firestore_platform_interface 5.8.3 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.0.3 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.1.22 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.3.11 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - code_builder 4.3.0 [built_collection built_value collection matcher meta] - collection 1.16.0 - connectivity_plus_platform_interface 1.2.3 [flutter meta plugin_platform_interface] - convert 3.1.1 [typed_data] - coverage 1.5.0 [args logging package_config path source_maps stack_trace vm_service] - crypto 3.0.2 [typed_data] - custom_navigator 0.3.0 [flutter] - dart_style 2.2.4 [analyzer args path pub_semver source_span] - dbus 0.7.8 [args ffi meta xml] - device_info_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - easy_logger 0.0.2 [flutter] - fake_async 1.3.1 [clock collection] - ffi 2.0.1 - file 6.1.2 [meta path] - firebase_analytics_platform_interface 3.3.11 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.1+2 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth_platform_interface 6.11.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.1.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.2 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.0.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.3.4 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_dynamic_links_platform_interface 0.2.3+19 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 4.2.4 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.2.4 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - fixnum 1.0.1 - flutter_appauth_platform_interface 5.2.0 [flutter plugin_platform_interface] - flutter_keyboard_visibility_linux 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_keyboard_visibility_macos 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - 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_keyboard_visibility_windows 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_plugin_android_lifecycle 2.0.7 [flutter] - flutter_secure_storage_linux 1.1.1 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 1.1.1 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.0 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.0.2 [flutter flutter_web_plugins flutter_secure_storage_platform_interface js] - flutter_secure_storage_windows 1.1.2 [flutter flutter_secure_storage_platform_interface] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - frontend_server_client 3.1.0 [async path] - fuchsia_remote_debug_protocol 0.0.0 [process vm_service file meta path platform] - glob 2.1.0 [async collection file path string_scanner] - google_maps_flutter_android 2.3.3 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface stream_transform] - google_maps_flutter_ios 2.1.12 [flutter google_maps_flutter_platform_interface stream_transform] - google_maps_flutter_platform_interface 2.2.4 [collection flutter plugin_platform_interface stream_transform] - graphs 2.2.0 [collection] - http 0.13.5 [async http_parser meta path] - http_multi_server 3.2.1 [async] - image 3.2.2 [archive meta xml] - io 1.0.3 [meta path string_scanner] - js 0.6.4 - json_annotation 4.7.0 [meta] - logging 1.1.0 - matcher 0.12.12 [stack_trace] - material_color_utilities 0.1.5 - meta 1.8.0 - mime 1.0.2 - modal_bottom_sheet 2.1.2 [flutter] - nested 1.0.0 [flutter] - nm 0.5.0 [dbus] - node_preamble 2.0.1 - package_config 2.1.0 [path] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.2 - path_drawing 1.0.1 [vector_math meta path_parsing flutter] - path_parsing 1.0.1 [vector_math meta] - path_provider 2.0.11 [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.20 [flutter path_provider_platform_interface] - path_provider_ios 2.0.11 [flutter path_provider_platform_interface] - path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.6 [flutter path_provider_platform_interface] - path_provider_platform_interface 2.0.5 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.3 [ffi flutter path path_provider_platform_interface win32] - permission_handler_android 10.2.0 [flutter permission_handler_platform_interface] - permission_handler_apple 9.0.7 [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] - pin_input_text_field 4.2.0 [flutter] - platform 3.1.0 - plugin_platform_interface 2.1.3 [meta] - pool 1.5.1 [async stack_trace] - process 4.2.4 [file path platform] - pub_semver 2.1.2 [collection meta] - pubspec_parse 1.2.1 [checked_yaml collection json_annotation pub_semver yaml] - shared_preferences_android 2.0.14 [flutter shared_preferences_platform_interface] - shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.1.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface] - shared_preferences_platform_interface 2.1.0 [flutter plugin_platform_interface] - shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.1.1 [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.2 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_gen 1.2.6 [analyzer async build dart_style glob meta path source_span yaml] - source_helper 1.3.3 [analyzer collection source_gen] - source_map_stack_trace 2.1.1 [path source_maps stack_trace] - source_maps 0.10.11 [source_span] - source_span 1.9.0 [collection path term_glyph] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.1 - string_scanner 1.1.1 [source_span] - sync_http 0.3.1 - term_glyph 1.2.1 - test_core 0.4.19 [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] - time 2.1.3 [clock] - timing 1.0.0 [json_annotation] - typed_data 1.3.1 [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_platform 1.0.0+1 - upower 0.7.0 [dbus] - url_launcher_android 6.0.21 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.1 [flutter plugin_platform_interface] - url_launcher_web 2.0.13 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface] - vector_math 2.1.2 - vm_service 9.0.0 - watcher 1.0.2 [async path] - web_socket_channel 2.2.0 [async crypto stream_channel] - webdriver 3.0.0 [archive matcher path stack_trace sync_http] - webkit_inspection_protocol 1.2.0 [logging] - win32 3.0.1 [ffi] - xdg_directories 0.2.0+2 [meta path process] - xml 6.1.0 [collection meta petitparser] - yaml 3.1.1 [collection source_span string_scanner] ```

darshankawar commented 1 year ago

Thanks for the report @SpiegelSoft Can you provide the complete error log that is triggered along with a minimal code sample that shows the behavior you are reporting ?

google-oss-bot commented 1 year ago

Hey @SpiegelSoft. 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!

google-oss-bot commented 1 year ago

Since there haven't been any recent updates here, I am going to close this issue.

@SpiegelSoft if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.