Flutter Web在Firebase托管中不起作用 [英] Flutter web not working in firebase hosting

查看:65
本文介绍了Flutter Web在Firebase托管中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在扑朔迷离的网络中使用Firestore.在本地(即Android Studio Chrome)中,一切正常.但是,当我在Firebase托管(firebase服务)中托管时,它无法正常工作.浏览器控制台显示错误.

I am using firestore in flutter web. Everything is working fine in local i.e,Android studio chrome. But when I hosted in firebase hosting (firebase serve) it's not working. 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

我不知道那行代码在我的flutter项目中写在哪里.有什么解决的办法吗?

I don't know where that line of code is written in my flutter project. Any help to solve this?

更新:该应用在Godaddy托管中运行正常,但在Firebase托管中运行不正常

Update: App working perfectly fine in Godaddy hosting but not in firebase hosting

推荐答案

我遇到了类似的问题.我通过确保在index.html文件中引用了所有正确的脚本来解决此问题.在此处的步骤5下查看可用的库: https://firebase.google.com/docs/web/setup#available-libraries

I have had similar issues. I fixed it by making sure I referenced all of the correct scripts in my index.html file. Look at the available libraries under Step 5 here: https://firebase.google.com/docs/web/setup#available-libraries

此处包含的脚本标签在脚本标签中不包括defer,您可能需要用它来解决问题,例如.<脚本延迟src = ...> .

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=...>.

这篇关于Flutter Web在Firebase托管中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆