How to use cloud_firestore in flutter for web and android?

☆樱花仙子☆ 提交于 2019-12-09 12:58:11

问题


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

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

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

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

Edit: 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!!

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


回答1:


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:

https://medium.com/@rody.davis.jr/how-to-build-a-native-cross-platform-project-with-flutter-372b9e4b504f

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.




回答2:


Web is not supported by the FlutterFire plugins. The plugin page has just instructions for Android and iOS.



来源:https://stackoverflow.com/questions/57948222/how-to-use-cloud-firestore-in-flutter-for-web-and-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!