Flutter Web App,Firebase.auth无法正常工作.尝试调用非函数,例如null. 'dart.global.firebase.auth' [英] Flutter Web App, Firebase.auth not working. Tried to call a non-function, such as null. 'dart.global.firebase.auth'
问题描述
我正在尝试使用Firebase Auth来实现一个简单的Flutter Web App.
I am trying to implement a simple Flutter Web App, with Firebase Auth.
我收到错误NoSuchMethodError: tried to call a non-function, such as null: 'dart.global.firebase.auth'
.
我看过其他帖子,例如和
I have looked at other posts, such as "NoSuchMethodError: tried to call a non-function, such as null: 'dart.global.firebase.auth'" when initializing auth() in flutter for web and Flutter web: tried to call a non-function, such as null: 'dart.global.firebase.storage.
两者都建议相同的解决方案:将firebase-auth.js添加到index.html
.我已经做到了.这是我的index.html
文件的样子:
Both suggest the same solution: add firebase-auth.js to index.html
. I already did it. This is how my index.html
file looks like:
<!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>
感谢您的帮助!
推荐答案
原来我放置了这个
<!-- 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-->
在错误的地方.
它应该在<head>
标记之内.
旁注,我两次有这个<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script>
,所以我删除了下面的一个.
Side note, I had this <script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script>
twice, so I deleted the one below.
最后,感谢David Iglesias在这里的回答: https://github.com/FirebaseExtended/flutterfire/issues/2860#issuecomment-651313186 .
Finally, thanks to David Iglesias for his answer here: https://github.com/FirebaseExtended/flutterfire/issues/2860#issuecomment-651313186.
这篇关于Flutter Web App,Firebase.auth无法正常工作.尝试调用非函数,例如null. 'dart.global.firebase.auth'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!