每当我启动我的 Flutter Web 应用程序时,我都会收到一条错误消息,告诉我 firebase.initializeapp 尚未被调用,但是代码在 android 上运行良好。
The New Flutter As Platform
PS: The Old way is Below
With the new support of Flutter as a platform on firebase. Everything is actually set up by firebase itself. just follow the steps and the connection will be done.
curl -sL https://firebase.tools | bash
curl -sL https://firebase.tools | bash
Firebase login
.dart pub global activate flutterfire_cli
flutterfire configure --project-name
main.dart
like followvoid main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
The Old Way, where we have to create separate platform-specific connections.
After setting the project on the firebase side, which I presume you have already done. You will have to configure the web part. like follows
Navigate to the root directory of your web build and open index.html. web->index.html
and the following code above the main.dart.js script tag check for lates code
<!-- ADD THIS BEFORE YOUR main.dart.js SCRIPT -->
<!-- The core Firebase JS SDK (always required for using any Firebase service) -->
<script src="https://www.gstatic.com/firebasejs/9.9.0//firebase-app.js"></script>
<!-- Firebase Auth SDK -->
<script src="https://www.gstatic.com/firebasejs/9.9.0//firebase-auth.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: '...',
authDomain: '...',
databaseURL: '...',
projectId: '...',
storageBucket: '...',
messagingSenderId: '...',
appId: '...',
}
// Initialize Firebase
firebase.initializeApp(firebaseConfig)
</script>
<!-- END OF FIREBASE INIT CODE -->
You will get the firebase config details from the settings of the web app in the firebase project. You can copy that from there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.