-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Hi,
I just created a basic Flutter Web project in VS Code. I am trying to use Firebase Auth, but I am getting the error NoSuchMethodError: tried to call a non-function, such as null: 'dart.global.firebase.auth'
.
I have searched online for solutions to this problem and they all point to adding firebase-auth.js to my index.html
file (eg: this stackoverflow post.)
I already did it, with no success. I even added some extra (firebase) stuff to the index.html
file, again, with no success.
This are the contents of my index.html
file:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="my_app">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
<title>my_app</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<!-- Firebase Configuration-->
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-auth.js"></script>
<!-- <script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-analytics.js"></script> -->
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-database.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
//my info
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// firebase.analytics();
</script>
<!-- End of Firebase Configuration-->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
Flutter doctor
This is the output of flutter doctor:
[√] Flutter (Channel beta, 1.19.0-4.2.pre, on Microsoft Windows [Versión 10.0.18362.900], locale es-CO)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.0)
[√] VS Code (version 1.46.1)
[√] Connected device (2 available)
• No issues found!
And this, the one for flutter doctor -v:
[√] Flutter (Channel beta, 1.19.0-4.2.pre, on Microsoft Windows [Versión 10.0.18362.900], locale es-CO)
• Flutter version 1.19.0-4.2.pre at C:\flutter
• Framework revision 9b9b543d92 (7 days ago), 2020-06-22 12:19:28 -0700
• Engine revision 9a28c3bcf4
• Dart version 2.9.0 (build 2.9.0-14.1.beta)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Android\sdk
• Platform android-29, build-tools 28.0.3
• ANDROID_HOME = C:\Android\sdk
• ANDROID_SDK_ROOT = C:\Android\sdk
• Java binary at: C:\Android Studio\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 (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.0)
• Android Studio at C:\Android Studio
• Flutter plugin version 46.0.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] VS Code (version 1.46.1)
• VS Code at C:\Users\My Username\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.12.0
[√] Connected device (2 available)
• Web Server • web-server • web-javascript • Flutter Tools
• Chrome • chrome • web-javascript • Google Chrome 83.0.4103.116
• No issues found!
Flutter run --verbose
Finally, this is the output for flutter run -d chrome --verbose
:
[ +29 ms] executing: [C:\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +154 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +3 ms] 9b9b543d9265484132c798adaab6caca52055b08
[ +1 ms] executing: [C:\flutter/] git tag --contains HEAD
[ +480 ms] Exit code 0 from: git tag --contains HEAD
[ +1 ms] 1.19.0-4.2.pre
[ +25 ms] executing: [C:\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[ +83 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[ +1 ms] origin/beta
[ ] executing: [C:\flutter/] git ls-remote --get-url origin
[ +72 ms] Exit code 0 from: git ls-remote --get-url origin
[ +1 ms] https://github.com/flutter/flutter.git
[ +181 ms] executing: [C:\flutter/] git rev-parse --abbrev-ref HEAD
[ +119 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[ +2 ms] beta
[ +134 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[ +2 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[ +10 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[ +10 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[ +12 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[ +19 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[ +16 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[ +3 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[ +2 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[ +2 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[ +2 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[ +2 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +55 ms] executing: C:\Android\sdk\platform-tools\adb.exe devices -l
[ +123 ms] List of devices attached
[ +23 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[ +5 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[ +8 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[ +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[ +20 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[ +15 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[ +2 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +251 ms] Found plugin cloud_firestore at C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.13.7\
[ +26 ms] Found plugin cloud_firestore_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore_web-0.1.1+2\
[ +32 ms] Found plugin firebase_auth at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.16.1\
[ +8 ms] Found plugin firebase_auth_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth_web-0.1.3+1\
[ +28 ms] Found plugin firebase_core at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.4.5\
[ +21 ms] Found plugin firebase_core_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core_web-0.1.1+2\
[ +13 ms] Found plugin firebase_database at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.1.6\
[ +19 ms] Found plugin firebase_storage at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_storage-3.1.6\
[ +168 ms] Found plugin cloud_firestore at C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.13.7\
[ +8 ms] Found plugin cloud_firestore_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore_web-0.1.1+2\
[ +26 ms] Found plugin firebase_auth at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.16.1\
[ +31 ms] Found plugin firebase_auth_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth_web-0.1.3+1\
[ +29 ms] Found plugin firebase_core at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.4.5\
[ +6 ms] Found plugin firebase_core_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core_web-0.1.1+2\
[ +3 ms] Found plugin firebase_database at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.1.6\
[ +9 ms] Found plugin firebase_storage at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_storage-3.1.6\
[ +159 ms] Generating C:\Users\Andres Silva C\Documents\Flutter Projects\my_project\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[ +238 ms] Launching lib\main.dart on Chrome in debug mode...
[ +175 ms] Updating assets
[ +260 ms] Syncing files to device Chrome...
[ +43 ms] Found plugin cloud_firestore at C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.13.7\
[ +6 ms] Found plugin cloud_firestore_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore_web-0.1.1+2\
[ +21 ms] Found plugin firebase_auth at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.16.1\
[ +16 ms] Found plugin firebase_auth_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth_web-0.1.3+1\
[ +3 ms] Found plugin firebase_core at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.4.5\
[ +6 ms] Found plugin firebase_core_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core_web-0.1.1+2\
[ +20 ms] Found plugin firebase_database at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.1.6\
[ +28 ms] Found plugin firebase_storage at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_storage-3.1.6\
[ +66 ms] Found plugin cloud_firestore at C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore-0.13.7\
[ +4 ms] Found plugin cloud_firestore_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\cloud_firestore_web-0.1.1+2\
[ +10 ms] Found plugin firebase_auth at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.16.1\
[ +18 ms] Found plugin firebase_auth_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth_web-0.1.3+1\
[ +2 ms] Found plugin firebase_core at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core-0.4.5\
[ +4 ms] Found plugin firebase_core_web at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_core_web-0.1.1+2\
[ +2 ms] Found plugin firebase_database at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_database-3.1.6\
[ +4 ms] Found plugin firebase_storage at C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_storage-3.1.6\
[ +70 ms] Generating C:\Users\Andres Silva C\Documents\Flutter Projects\my_project\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[ +145 ms] <- reset
[ +30 ms] C:\flutter\bin\cache\dart-sdk\bin\dart.exe --disable-dart-dev --old_gen_heap_size=2000 C:\flutter\bin\cache\artifacts\engine\windows-x64\frontend_server.dart.snapshot
--sdk-root C:\flutter\bin\cache\flutter_web_sdk/ --incremental --target=dartdevc --debugger-module-names -Ddart.developer.causal_async_stacks=true --output-dill
C:\Users\ANDRES~2\AppData\Local\Temp\flutter_tools.b87a850e\flutter_tool.b6859297\app.dill --libraries-spec file:///C:/flutter/bin/cache/flutter_web_sdk/libraries.json --packages
.packages -Ddart.vm.profile=false -Ddart.vm.product=false
--bytecode-options=source-positions,local-var-info,debugger-stops,instance-field-initializers,keep-unreachable-code,avoid-closure-call-instructions --enable-asserts
--track-widget-creation --filesystem-root C:\Users\ANDRES~2\AppData\Local\Temp\flutter_tools.b87a850e\flutter_tools.e5c4f0be --filesystem-scheme org-dartlang-app
--initialize-from-dill build\cache.dill.track.dill --platform file:///C:/flutter/bin/cache/flutter_web_sdk/kernel/flutter_ddc_sdk.dill
[ +51 ms] <- compile org-dartlang-app:/web_entrypoint.dart
[+26674 ms] Syncing files to device Chrome... (completed in 27.206ms, longer than expected)
[ +7 ms] Synced 24.2MB.
[ +7 ms] <- accept
[ +527 ms] [CHROME]:
[ +280 ms] [CHROME]:DevTools listening on ws://127.0.0.1:63004/devtools/browser/c6b4e05f-4e4b-4319-92df-a11b61c39224
[+14698 ms] Debug service listening on ws://127.0.0.1:63050/3Cp0rHcnYv0=
[+1557 ms] Debug service listening on ws://127.0.0.1:63050/3Cp0rHcnYv0=
[ +8 ms] Warning: Flutter's support for web development is not stable yet and hasn't
[ +10 ms] been thoroughly tested in production environments.
[ ] For more information see https://flutter.dev/web
[ +2 ms] To hot restart changes while running, press "r" or "R".
[ +2 ms] For a more detailed help message, press "h". To quit, press "q".
[+1532 ms] Testing
[ +27 ms] Instance of 'FirebaseAuth'
[+1295 ms] ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
[ +7 ms] The following JSNoSuchMethodError was thrown building MyApp(dirty):
[ +2 ms] NoSuchMethodError: tried to call a non-function, such as null: 'dart.global.firebase.auth'
[ +3 ms] The relevant error-causing widget was:
[ +1 ms] MyApp
[ +2 ms] file:///C:/Users/Andres%20Silva%20C/Documents/Flutter%20Projects/my_project/lib/main.dart:12:10
[ +2 ms] When the exception was thrown, this was the stack:
[ +1 ms] packages/firebase/src/top_level.dart 87:34 auth$
[ +3 ms] packages/firebase_auth_web/firebase_auth_web.dart 20:12 [_getAuth]
[ +19 ms] packages/firebase_auth_web/firebase_auth_web.dart 190:32 onAuthStateChanged
[ +84 ms] packages/firebase_auth/src/firebase_auth.dart 24:71 get onAuthStateChanged
[ +195 ms] packages/my_project/logic/services/auth.dart 32:10 get user
[ +11 ms] packages/my_project/main.dart 29:41 build
[ +7 ms] packages/flutter/src/widgets/framework.dart 4585:28 build
[ +3 ms] packages/flutter/src/widgets/framework.dart 4511:15 performRebuild
[ +65 ms] packages/flutter/src/widgets/framework.dart 4227:5 rebuild
[ +28 ms] packages/flutter/src/widgets/framework.dart 4490:5 [_firstBuild]
[ +32 ms] packages/flutter/src/widgets/framework.dart 4485:5 mount
[ +4 ms] packages/flutter/src/widgets/framework.dart 3455:13 inflateWidget
[ +3 ms] packages/flutter/src/widgets/framework.dart 3223:18 updateChild
[ +50 ms] packages/flutter/src/widgets/binding.dart 1132:16 [_rebuild]
[ +40 ms] packages/flutter/src/widgets/binding.dart 1103:5 mount
[ +5 ms] packages/flutter/src/widgets/binding.dart 1045:16 <fn>
[ +3 ms] packages/flutter/src/widgets/framework.dart 2612:19 buildScope
[ +5 ms] packages/flutter/src/widgets/binding.dart 1044:12 attachToRenderTree
[ +56 ms] packages/flutter/src/widgets/binding.dart 924:24 attachRootWidget
[ +12 ms] packages/flutter/src/widgets/binding.dart 906:7 <fn>
[ +47 ms] C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19 internalCallback
[ +52 ms] ════════════════════════════════════════════════════════════════════════════════════════════════════
Note: The lines Testing
and Instance of 'FirebaseAuth'
were prints for debugging.
Thanks for your help!