Flutter Web和Firebase身份验证TypeError:无法读取未定义的属性'app'
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flutter Web和Firebase身份验证TypeError:无法读取未定义的属性'app'相关的知识,希望对你有一定的参考价值。
有人可以帮我吗?我尝试使用Flutter基于Google Firebase Auth和Cloud Firestore构建Web应用程序。 android上的项目运行良好,我可以与用户合作,并且可以从Cloud Firestore数据库中获取数据。我已经制作了第二个应用程序(webapp),执行Firebase文档中描述的所有步骤(webapp已注册,托管在Firebase上),并将所有依赖项插入pubspec.yaml
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for ios style icons.
cupertino_icons: ^0.1.3
firebase_core: ^0.4.4+3
firebase: ^7.3.0
firebase_auth: ^0.16.0
像这样修改index.html:
<body>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="/__/firebase/7.14.3/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="/__/firebase/7.14.3/firebase-analytics.js"></script>
<!-- Add Firebase products that you want to use -->
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.2/firebase-firestore.js"></script>
<!-- Initialize Firebase -->
<script src="/__/firebase/init.js"></script> <!-- 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 -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script>
var firebaseConfig = {
apiKey: "XXXXXXXXXX-6EL5qIBxWjurRQMcK3pf9W-o",
authDomain: "xxxxxxxx.firebaseapp.com",
databaseURL: "https://xxxxxxxx.firebaseio.com",
projectId: "xxxxxxxx",
storageBucket: "xxxxxxxx.appspot.com",
messagingSenderId: "xxxxxxxx6198",
appId: "1:xxxxxxxx16198:web:cde3457e8dc734d045d227",
measurementId: "X-XXXXXXXXXX"
};
firebase.initializeApp(firebaseConfig);
firebase.auth();
firebase.analytics();
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
但是当我尝试登录或注册时,Android Studio会抛出此错误消息:
TypeError: Cannot read property 'app' of undefined
at Object.app$ [as app] (http://localhost:53262/packages/firebase/src/top_level.dart.lib.js:72:56)
at firebase_auth_web.FirebaseAuthWeb.new.[_getAuth] (http://localhost:53262/packages/firebase_auth_web/firebase_auth_web.dart.lib.js:42:27)
at firebase_auth_web.FirebaseAuthWeb.new.signInWithCredential (http://localhost:53262/packages/firebase_auth_web/firebase_auth_web.dart.lib.js:197:34)
at signInWithCredential.next (<anonymous>)
at runBody (http://localhost:53262/dart_sdk.js:43135:34)
at Object._async [as async] (http://localhost:53262/dart_sdk.js:43163:7)
at firebase_auth_web.FirebaseAuthWeb.new.signInWithCredential (http://localhost:53262/packages/firebase_auth_web/firebase_auth_web.dart.lib.js:196:20)
at firebase_auth.FirebaseAuth.__.signInWithCredential (http://localhost:53262/packages/firebase_auth/firebase_auth.dart.lib.js:324:90)
at signInWithCredential.next (<anonymous>)
此异常是什么意思?我怎么了非常感谢您的帮助!
答案
修复依赖项。这对我有帮助
依赖关系:扑:SDK:颤振firebase_auth:firebase_auth_web:
以上是关于Flutter Web和Firebase身份验证TypeError:无法读取未定义的属性'app'的主要内容,如果未能解决你的问题,请参考以下文章
如何为 Flutter Web 添加 Firebase 预构建的身份验证 UI?
Flutter Web 中的 Firebase Phone 身份验证
Flutter Web和Firebase身份验证TypeError:无法读取未定义的属性'app'
我是 Flutter Web 的新手,如何使用 Firebase 电话身份验证对用户进行身份验证,有没有办法让用户保持登录状态?