Solvedflutterfire πŸ› [cloud_firestore_web] Collection get throws Error: [cloud_firestore/unknown] NoSuchMethodError: invalid member on null: 'includeMetadataChanges'

Bug report

Describe the bug
When trying to read data from a collection (either get or snapshot), the following error is thrown:

Error: [cloud_firestore/unknown] NoSuchMethodError: invalid member on null: 'includeMetadataChanges'
    at Object.throw_ [as throw] (http://localhost:5000/dart_sdk.js:4339:11)
    at collection_reference_web.CollectionReferenceWeb.new.get (http://localhost:5000/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:321:21)
    at get.next (<anonymous>)
    at http://localhost:5000/dart_sdk.js:37679:33
    at _RootZone.runUnary (http://localhost:5000/dart_sdk.js:37533:58)
    at _FutureListener.thenAwait.handleValue (http://localhost:5000/dart_sdk.js:32507:29)
    at handleValueCallback (http://localhost:5000/dart_sdk.js:33054:49)
    at Function._propagateToListeners (http://localhost:5000/dart_sdk.js:33092:17)
    at _Future.new.[_completeWithValue] (http://localhost:5000/dart_sdk.js:32935:23)

This does not occur with a single document read. This makes it impossible to use FireStore.

Steps to reproduce

Steps to reproduce the behavior:

  • Create Firebase project and create sample collection with FireStore
  • Try to read it:
    await _firestore .collection('sampleCollection') .get();

Expected behavior

Data is correctly read.


Additional context

Currently working on v0.18.3, tried reverting to 0.18.0, but encountered the same problem. Reverting to even earlier version results in too many breaking changes.


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 beta, 1.23.0-18.1.pre, on Microsoft Windows [Version 10.0.18362.1139], locale en-GB)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Chrome - develop for the web
[√] Android Studio (version 3.6)
[√] VS Code (version 1.51.1)
[√] Connected device (3 available)

β€’ No issues found!

Flutter dependencies

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

Click To Expand
Dart SDK 2.11.0-213.1.beta
Flutter SDK 1.23.0-18.1.pre

dependencies:
- cloud_firestore 0.14.3 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web]
- crypto 2.1.5 [collection convert typed_data]
- cupertino_icons 1.0.0
- dio 3.0.10 [http_parser path]
- dio_flutter_transformer 3.0.2 [flutter dio]
- enum_to_string 1.0.13
- equatable 1.2.5 [collection meta]
- firebase_auth 0.18.3 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter]
- firebase_core 0.5.2 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- get_it 5.0.1 [async meta]
- google_sign_in 4.5.5 [google_sign_in_platform_interface flutter meta google_sign_in_web]
- http 0.12.2 [http_parser path pedantic]
- injectable 1.0.5 [get_it]
- json_annotation 3.1.0
- logger 0.9.4
- pretty_dio_logger 1.1.1 [dio]
- provider 4.3.2+2 [flutter nested collection]
- retrofit 1.3.4+1 [meta dio]
- rxdart 0.24.1
- shared_preferences 0.5.12+2 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- stats 1.0.0 [json_annotation]

dev dependencies:
- build_runner 1.10.3 [args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style glob graphs http_multi_server io js logging meta mime path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- 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]
- injectable_generator 1.0.6 [build source_gen path glob analyzer injectable collection]
- json_serializable 3.5.0 [analyzer build build_config json_annotation meta path source_gen]
- lint 1.3.0
- retrofit_generator 1.4.0 [dio source_gen built_collection code_builder tuple retrofit analyzer dart_style build]

transitive dependencies:
- _fe_analyzer_shared 11.0.0 [meta]
- analyzer 0.40.4 [_fe_analyzer_shared args charcode cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- args 1.6.0
- async 2.5.0-nullsafety.1 [collection]
- boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner]
- build 1.5.0 [analyzer async convert crypto logging meta path glob]
- build_config 0.4.2 [checked_yaml json_annotation meta path pubspec_parse yaml]
- build_daemon 2.1.4 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 1.4.2 [analyzer build crypto graphs logging meta path package_config pool pub_semver]
- build_runner_core 6.0.3 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml]     
- built_collection 4.3.2 [collection quiver]
- built_value 7.1.0 [built_collection collection fixnum quiver]
- characters 1.1.0-nullsafety.3
- charcode 1.2.0-nullsafety.1
- checked_yaml 1.0.2 [json_annotation source_span yaml]
- cli_util 0.2.0 [path]
- clock 1.1.0-nullsafety.1
- cloud_firestore_platform_interface 2.2.0 [flutter meta collection firebase_core plugin_platform_interface]
- cloud_firestore_web 0.2.1 [flutter flutter_web_plugins http_parser meta firebase_core firebase_core_web cloud_firestore_platform_interface js]
- code_builder 3.5.0 [built_collection built_value collection matcher meta]
- collection 1.15.0-nullsafety.3
- convert 2.1.1 [charcode typed_data]
- dart_style 1.3.8 [analyzer args path source_span]
- fake_async 1.2.0-nullsafety.1 [clock collection]
- ffi 0.1.3
- file 5.2.1 [intl meta path]
- firebase_auth_platform_interface 2.1.3 [flutter meta firebase_core plugin_platform_interface]
- firebase_auth_web 0.3.2 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_platform_interface js]
- firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.1 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
- fixnum 0.10.11
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- glob 1.2.0 [async collection node_io path pedantic string_scanner]
- google_sign_in_platform_interface 1.1.2 [flutter meta quiver]
- google_sign_in_web 0.9.2 [google_sign_in_platform_interface flutter flutter_web_plugins meta js]
- graphs 0.2.0
- http_multi_server 2.2.0 [async]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- intl 0.16.1 [path]
- io 0.3.4 [charcode meta path string_scanner]
- js 0.6.3-nullsafety.1
- logging 0.11.4
- matcher 0.12.10-nullsafety.1 [stack_trace]
- meta 1.3.0-nullsafety.4
- mime 0.9.7
- nested 0.0.4 [flutter]
- node_interop 1.1.1 [js]
- node_io 1.1.1 [node_interop path]
- package_config 1.9.3 [path charcode]
- path 1.8.0-nullsafety.1
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_platform_interface 1.0.3 [flutter meta platform plugin_platform_interface]
- path_provider_windows 0.0.4+1 [path_provider_platform_interface meta path flutter ffi win32]
- pedantic 1.9.2 [meta]
- platform 2.2.1
- plugin_platform_interface 1.0.3 [meta]
- pool 1.4.0 [async stack_trace]
- process 3.0.13 [file intl meta path platform]
- pub_semver 1.4.4 [collection]
- pubspec_parse 0.1.5 [checked_yaml json_annotation pub_semver yaml]
- quiver 2.1.3 [matcher meta]
- shared_preferences_linux 0.0.2+2 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 0.0.1+10 [shared_preferences_platform_interface flutter]
- shared_preferences_platform_interface 1.0.4 [meta flutter]
- shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
- shared_preferences_windows 0.0.1+1 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows]
- shelf 0.7.9 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 0.2.3 [shelf web_socket_channel stream_channel]
- sky_engine 0.0.99
- source_gen 0.9.7+1 [analyzer async build dart_style glob meta path pedantic source_span]
- source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph]
- stack_trace 1.10.0-nullsafety.2 [path]
- stream_channel 2.1.0-nullsafety.1 [async]
- stream_transform 1.2.0
- string_scanner 1.1.0-nullsafety.1 [charcode source_span]
- term_glyph 1.2.0-nullsafety.1
- test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timing 0.1.1+2 [json_annotation]
- tuple 1.0.3 [quiver]
- typed_data 1.3.0-nullsafety.3 [collection]
- vector_math 2.1.0-nullsafety.3
- watcher 0.9.7+15 [async path pedantic]
- web_socket_channel 1.1.0 [async crypto stream_channel]
- win32 1.7.3 [ffi]
- xdg_directories 0.1.2 [meta path process]
- yaml 2.2.1 [charcode collection string_scanner source_span]

43 Answers

βœ”οΈAccepted Answer

I was getting this same issue. I did not downgrade my firebase core in the pubspec.yaml, but instead I replaced the version in my index.html and I don't see the error anymore, so I can confirm this is an issue with the latest version of the package.

NOT working:

<script src="https://www.gstatic.com/firebasejs/8.0.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.0.2/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.0.2/firebase-firestore.js"></script>

Working:

<script src="https://www.gstatic.com/firebasejs/8.0.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.0.2/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>

Notice how I had to replace the version 8.0.2 with 7.20.0 for firebase-firestore.js for it to work properly.

My pubspec.yaml contains the following:

firebase_core: ^0.5.2
cloud_firestore: ^0.14.3

Other Answers:

There are many spots where the current latest version of 8.21.1 is mentioned in official documentation for Javascript web SDK, so it can be frustrating that there isn't consistency and things break when using with Flutter.

I wanted the emulators only available in >8.0.0 (i.e. auth and firestore), and the below configuration finally worked for me.

<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.0.1/firebase-firestore.js"></script>

From my pubspec.yaml:

firebase_core: ^0.5.3
firebase_analytics: ^6.3.0
firebase_auth: ^0.18.4+1
cloud_firestore: ^0.14.4

It looks as though the issue begins with https://www.gstatic.com/firebasejs/8.0.2/firebase-firestore.js.

Not to mention, version 7.20.0 is the officially recommended version. Don't complain because you upgraded, be happy you found the solution and move on.

This is what is currently on the official FlutterFire docs:
image

Reproducible on the latest master 1.24.0-8.0.pre.268 with
<script src="https://www.gstatic.com/firebasejs/8.0.2/firebase-firestore.js"></script>
but not with
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>
(which is still recommended at the official setup guide)

flutter doctor -v
[√] Flutter (Channel master, 1.24.0-8.0.pre.268, on Microsoft Windows [Version 10.0.19041.630], locale et-EE)
    β€’ Flutter version 1.24.0-8.0.pre.268 at C:\Development\flutter_master
    β€’ Framework revision e803b13f01 (30 minutes ago), 2020-11-16 22:55:59 -0800
    β€’ Engine revision f0e80100f7
    β€’ Dart version 2.12.0 (build 2.12.0-49.0.dev)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    β€’ Android SDK at C:\Users\marku\AppData\Local\Android\sdk
    β€’ Platform android-30, build-tools 30.0.2
    β€’ Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283\jre\bin\java
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    β€’ All Android licenses accepted.

[√] Chrome - develop for the web
    β€’ Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.7)
    β€’ Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    β€’ Visual Studio Community 2019 version 16.7.30621.155
    β€’ Windows 10 SDK version 10.0.18362.0

[√] Android Studio (version 4.1.0)
    β€’ Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283
    β€’ Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    β€’ Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    β€’ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] IntelliJ IDEA Ultimate Edition (version 2020.2)
    β€’ IntelliJ at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\202.7660.26
    β€’ Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    β€’ Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[√] Connected device (4 available)
    β€’ Windows (desktop) β€’ windows    β€’ windows-x64    β€’ Microsoft Windows [Version 10.0.19041.630]
    β€’ Web Server (web)  β€’ web-server β€’ web-javascript β€’ Flutter Tools
    β€’ Chrome (web)      β€’ chrome     β€’ web-javascript β€’ Google Chrome 86.0.4240.198
    β€’ Edge (web)        β€’ edge       β€’ web-javascript β€’ Microsoft Edge 86.0.622.68

β€’ No issues found!

Notice how I had to replace the version 8.0.2 with 7.20.0 for firebase-firestore.js for it to work properly.

Thanks @tapizquent, this saved me! To clarify, you do not need to change the version in the pubspec.yaml for this to work.

More Issues: