Flutter新手-我怀疑在尝试设置Firebase Auth时错过了一些非常简单的东西。
一直在网上浏览解决方案。大多数人要求您仔细检查firebase-auth.js是否正确包含在index.html文件中。这就完成了,下面的index.html文件。
这篇文章和这篇文章表明,这个问题可以通过将我的firebase配置移动到index.html文件的head部分来解决。不确定为什么会出现这种情况,但尝试过了,没有看到任何变化。
我的index.html文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter application.">
<!-- 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="test_auth">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
<title>test_auth</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 -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<!-- Firebase Configuration-->
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.17.1/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/firebase/7.17.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.17.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.17.1/firebase-analytics.js"></script>
<script>
var firebaseConfig = {
//my deets
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
firebase.auth();
</script>
<!-- End of Firebase Configuration-->
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
我的pubspec.yaml依赖:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
firebase_core: ^0.4.5
firebase_auth: ^0.16.1
cloud_firestore: ^0.13.7
flutter doctor -v
[✓] Flutter (Channel master, 1.21.0-6.0.pre.170, on Mac OS X 10.15.2 19C57, locale en-CA)
• Flutter version 1.21.0-6.0.pre.170 at /Users/olisno/development/flutter
• Framework revision 4c7fae93aa (6 hours ago), 2020-08-04 10:44:43 -0700
• Engine revision 033dd45607
• Dart version 2.10.0 (build 2.10.0-2.0.dev 0f0e04ec3a)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at /Users/olisno/Library/Android/sdk
• Platform android-30, build-tools 30.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.6, Build version 11E708
• CocoaPods version 1.9.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 47.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.47.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.12.2
[✓] Connected device (3 available)
• iPhone SE (2nd generation) (mobile) • 7F1F5A6D-F82D-46FB-B71B-371887713467 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 84.0.4147.105
• No issues found!
谢谢你的任何提示!
在我的案例中,我只为firebase_auth
版本更新了主要版本并解决了它。
_core的主要版本仍然是1,但_auth的主要版本似乎更新得相对频繁。
将pubspec.yaml
中的firebase_auth: ^1.0.1
更改为firebase_auth: ^3.0.1
。似乎您不需要在web/index.html
中添加CDN链接。pub包将自动生成head标签的内部。