flutter web TypeError: dart.global.firebase.storage 不是函数
Posted
技术标签:
【中文标题】flutter web TypeError: dart.global.firebase.storage 不是函数【英文标题】:flutter web TypeError: dart.global.firebase.storage is not a function 【发布时间】:2021-04-29 17:53:09 【问题描述】:我正在用 Flutter 构建一个网络应用程序,试图将照片添加到 Firebase 存储中。
我遇到了这个错误,大多数帖子都说通过添加来解决
https://www.gstatic.com/firebasejs/8.2.4/firebase-database.js"
但我有
还有什么可能导致 TypeError: dart.global.firebase.storage is not a function
<body>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.2.4/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/8.2.4/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.4/firebase-firestore.js"></script>
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig =
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
;
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
</script>
【问题讨论】:
【参考方案1】:在 index.html 中添加这个,它会起作用(看你把它插入到正确的地方)
..................
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
<script src="https://www.gstatic.com/firebasejs/7.17.1/firebase-firestore.js"></script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
【讨论】:
【参考方案2】:我遇到了同样的问题,并通过为 firebase-storage 添加另一个脚本来修复它
...
<script src="https://www.gstatic.com/firebasejs/8.2.4/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.4/firebase-storage.js"></script>
...
【讨论】:
以上是关于flutter web TypeError: dart.global.firebase.storage 不是函数的主要内容,如果未能解决你的问题,请参考以下文章
flutter web TypeError: dart.global.firebase.storage 不是函数
将firebase添加到flutter web时出现问题,TypeError:无法读取未定义的属性(读取“应用程序”)
Flutter Web和Firebase身份验证TypeError:无法读取未定义的属性'app'
Flutter Web 错误 TypeError: dart.global.firebase.analytics is not a function