简体   繁体   English

在 Flutter 网页和移动应用中使用 Firebase

[英]Use Firebase in both Flutter web AND mobile app

I'm working on a Flutter app, compiled in both web AND mobile version.我正在开发一个 Flutter 应用程序,在网络和移动版本中编译。 Everything worked like a charm until I decided to use Firebase.在我决定使用 Firebase 之前,一切都很顺利。

I found that there are many libs that allow to use Firebase in Flutter, for mobile apps.我发现有许多库允许在 Flutter 中为移动应用程序使用 Firebase。 I also found a lib that allows to use Firebase in Flutter web app.我还找到了一个允许在 Flutter Web 应用程序中使用 Firebase 的库。

The problem is: Firebase plugin for web version is using "dart:html" , which isn't supported for mobile versions of Flutter apps.问题是:Web 版本的 Firebase 插件正在使用"dart:html" ,而 Flutter 应用程序的移动版本不支持该插件。 On the other side, mobile libs aren't supported by web versions and I always get a PlatformException when using them in web app.另一方面,Web 版本不支持移动库,在 Web 应用程序中使用它们时,我总是得到PlatformException

So here is my question: Does anyone know a Flutter's Firebase lib, that works on BOTH mobile AND web versions, so that I only have to compile in the platform I want, without having to change the code before?所以这是我的问题:有谁知道 Flutter 的 Firebase 库,它适用于移动和网络版本,所以我只需要在我想要的平台上编译,而不必更改代码?

EDIT: I know there is a way to write specific code for Android or iOS version, but I can't find any clue for writing specific code for the web version.编辑:我知道有一种方法可以为 Android 或 iOS 版本编写特定代码,但我找不到任何为 Web 版本编写特定代码的线索。 This should be another way to solve the problem...这应该是解决问题的另一种方法......

Any idea?任何的想法?

At the moment there is no single Flutter+Firebase library that works for both web and mobile apps, so you will need to use two (incompatible) libraries.目前没有一个 Flutter+Firebase 库同时适用于 Web 和移动应用程序,因此您需要使用两个(不兼容的)库。

Work is being done to rectify that situation, but there's no timeline for its release.正在努力纠正这种情况,但没有发布时间表。

Also see:另见:

What firebase plugins are you using??你用的是什么firebase插件?? As there are only limited firebase plugins avalaible to use on web which includes firebase_analytics firebase_auth cloud_firestore cloud_functions firebase_messaging firebase_storage firebase_core因为只有有限的火力插件avalaible对网络使用,其中包括firebase_analytics firebase_auth cloud_firestore cloud_functions firebase_messaging firebase_storage firebase_core

if you are using any firebase plugin other than these then they are not supported for web如果您使用除这些之外的任何 firebase 插件,则它们不支持 Web

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

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