如何在Flutter中为网络和Android使用cloud_firestore? [英] How to use cloud_firestore in flutter for web and android?

查看:56
本文介绍了如何在Flutter中为网络和Android使用cloud_firestore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Flutter应用程序,该应用程序可以按预期在Android上运行,但是如果我要针对Web进行编译,则会出现错误.

I have a Flutter app which works on Android as expected but if I want to compile it for Web I get an error.

它必须处理依赖项cloud_firestore.如果我使用依赖项firebase,则可以在网络上正常运行,但现在在android上无法运行..

It has to do something with the dependency cloud_firestore. If I use the dependency firebase it works fine on the web but on android now not..

这是我使用cloud_firestore(针对Web进行编译)时收到的错误消息:

This is the error message I get using cloud_firestore (compiling for web):

Skipping compiling pay_balance|lib/main_web_entrypoint.dart with ddc because some of its
transitive libraries have sdk dependencies that not supported on this platform:

firebase_core|lib/firebase_core.dart

https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings

有人可以帮助我吗?也许对firestore有另一个依赖关系(我找不到在Web和android上工作的其他对象).

Can anybody help me? Maybe with another dependency for firestore (I did not find others which are working on web and android)..

我已经将firebase-dart插件用于网络了! ->仅适用于网络,但不适用于android->我同时需要两者!

I have used the firebase-dart plugin for web!! -> Only works on the web but not in android for me -> I need something for both at the same time!!

或者有什么方法可以在导入cloud_firestore时使用两个软件包而不会在网络上出现编译错误?

Or is there a Way I can use both packages without getting a compling error for the web when I import cloud_firestore?

推荐答案

如果您想在Web和Mobile上使用Firebase,则必须发挥创意.我创建了fb_auth插件,该插件在iOS和Android上使用Mobile SDK firebase_auth,在Web上使用firebase软件包.这将为您提供一个用于auth的插件.

If you want to use Firebase on Web and Mobile you have to get creative. I created the fb_auth plugin that uses the Mobile SDK firebase_auth on iOS and Android and the firebase package on web. This will give you a single plugin for auth.

https://pub.dev/packages/fb_auth

我正在从事仓储和仓储工作,但还没有准备好.

Im working on firstore and storage but they are not ready yet.

我还创建了一篇有关如何用颤振做到这一点的文章:

I have also created an article on how to do this with flutter:

您必须使用动态导入,以便在编译时树会摇晃不需要的内容,并且不会引发错误.

You have to use dynamic imports so that at compile time it tree shakes what it doesn't need and will not throw an error.

当前,这是在同一项目中正式使用这两个插件的唯一方法.

Currently this is the only way to officially use both plugins in the same project.

这篇关于如何在Flutter中为网络和Android使用cloud_firestore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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