简体   繁体   English

Flutter web 在 firebase 托管中不工作

[英]Flutter web not working in firebase hosting

I am using firestore in flutter web.我在 flutter web 中使用 Firestore。 Everything is working fine in local ie,Android studio chrome.在本地,即 Android studio chrome 中一切正常。 But when I hosted in firebase hosting (firebase serve) it's not working.但是当我在 firebase 托管(firebase 服务)中托管时,它不起作用。 The browser console giving error.浏览器控制台给出错误。

Uncaught TypeError: firebase.firestore is not a function
    at Object.arO (top_level.dart:125)
    at cloud_firestore_web.dart:26
    at alN.a (async_patch.dart:308)
    at alN.$2 (async_patch.dart:333)
    at Object.N (async_patch.dart:238)
    at Object.T8 (main.dart:8)
    at js_helper.dart:3221
    at js_helper.dart:3221
    at dartProgram (js_helper.dart:3221)
    at js_helper.dart:3221

pubsec.yaml pubsec.yaml

name: chitragupta
description: Monthly expenditure tacker

version: 1.2.0+2

environment:
  sdk: ">=2.2.2 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.2
  flutter_launcher_icons: ^0.7.2
  material_design_icons_flutter: ^4.0.5145
  firebase_core: ^0.4.3+2 #For firebase database
  firebase_auth: ^0.16.0 #firebase Authentication
  shared_preferences: ^0.5.7 #for local storage
  shared_preferences_web: ^0.1.2+4
  intl: ^0.16.0
  flutter_datetime_picker: ^1.2.6
  fluttertoast: ^3.1.3
  package_info: ^0.4.0+13
  image_picker: ^0.6.2+3
  http: ^0.12.0+2
  charts_flutter: ^0.8.1
  flutter_svg: ^0.17.4
  cloud_firestore: ^0.13.5


dev_dependencies:
  flutter_test:
    sdk: flutter


flutter:

  uses-material-design: true
  assets:
    - assets/

flutter_icons:
  image_path: "assets/logo.png"
  android: true
  ios: true

I don't know where that line of code is written in my flutter project.我不知道那行代码在我的 flutter 项目中写在哪里。 Any help to solve this?有什么帮助解决这个问题吗?

Update: App working perfectly fine in Godaddy hosting but not in firebase hosting更新:应用程序在 Godaddy 托管中运行良好,但在 firebase 托管中无法正常运行

I have had similar issues.我有过类似的问题。 I fixed it by making sure I referenced all of the correct scripts in my index.html file.我通过确保在我的 index.html 文件中引用了所有正确的脚本来修复它。 Look at the available libraries under Step 5 here: https://firebase.google.com/docs/web/setup#available-libraries在此处查看第 5 步下的可用库: https://firebase.google.com/docs/web/setup#available-libraries

The script tags that are included here do not include defer in the script tag and you may need that to fix your issue eg.此处包含的脚本标签不包含脚本标签中的延迟,您可能需要它来解决您的问题,例如。 <script defer src=...> . <script defer src=...>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM