Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use cloud_firestore in flutter for web and android?

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?

like image 984
Maxi Avatar asked Sep 15 '19 21:09

Maxi


People also ask

How to add Cloud Firestore to your flutter application?

Click CTRL + S to save, and you have successfully added Cloud Firestore to your Flutter application! There are two ways to add data to the Cloud Firestore, first way is to specifiy the document name and the second way Cloud Firestore will generate a random id, let us see both cases.

What is Cloud Firestore and why should I use it?

Working with Cloud Firestore can save Flutter developers a lot of time over managing their own database and API, however getting started can often present a challenge. In this article we'll exame some of the more common use cases for Cloud Firestore in Flutter.

How do I integrate Cloud Firestore with Firebase?

The Cloud Firestore SDK is also available as an npm package. You'll need to manually require both Firebase and Cloud Firestore. Follow the instructions to add Firebase to your Web app . The Cloud Firestore SDK is available as an npm package. You'll need to import both Firebase and Cloud Firestore.

How to configure Cloud Firestore to start in test mode?

In the Secure rules for Cloud Firestore dialog, select Start in test mode, then click Next. On the next screen, select Cloud Firestore location. I suggest selecting nam5 (us-central) . However, you can select according to your preference. Test mode allows any user to read and write to your database, which is convenient during development.


2 Answers

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.

like image 106
Rody Davis Avatar answered Oct 19 '22 02:10

Rody Davis


EDIT: cloud_firestore now added

Two of the FutterFire plugins are now supported for web. FlutterFire plugins supporting web firebase_auth and firebase_core

cloud_firestore is now also supported

like image 20
flutter Avatar answered Oct 19 '22 03:10

flutter