Testing a Flutter app against Firestore using emulator

601 views
Skip to first unread message

Shaiwal Singh

unread,
Mar 18, 2020, 2:04:46 PM3/18/20
to Firebase Google Group
Hi,

Im trying to do an end to end test of a Flutter app that uses Firestore against the Firestore emulator (using: firebase emulators:start —only firestore) to validate some firestore cloud functions that the app uses.

Even after making the appropriate Firestore.settings updates I am unable to run against the emulator.  Instead the app ends up runing in offline mode.

I am using the cloud_firestore package (https://pub.dev/packages/cloud_firestore)

My settings code is:
if (argRunOnEmulator){
_firestore.settings(
host: "localhost:8080",
persistenceEnabled: false,
sslEnabled: false
);
}

There seems to be very limited documentation online on how to get a Flutter app using cloud_firestore configured to run against a firestore emulator.

Questions I have are:
1. Any pointers on docs and tips on how to get the above combo of packages/technologies working would be appreciated.
2. I have already disabled the firebase auth code in the app (there was some video online suggesting that it might interfere with working with the emulator).  But I do still call to FirebaseAuth.instance (i.e. create a FirebaseAuth instance) and the project also uses firebase crashlytics, firebase storage and firebase messaging.  Other than crashlytics, the rest of the dependencies are not being actively utilized in the code path that I am testing.  Do I need to disable those too to get this working?
3. Does the cloud_firestore package have any limitations running against the emulator
4. Are there any changes that I need to make to the GoogleService-Info.plist (iOS) and google-services.json file to get this working?

Thx
Shaiwal

Suzuki Tomohiro

unread,
Mar 18, 2020, 3:21:23 PM3/18/20
to fireba...@googlegroups.com
Hi Shaiwal,

I recently implemented a driver test that uses Firestore emulator (firebase command 7.15.0) with cloud_firestore.
They worked.

Regards,
Tomo


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/006F442E-7798-456F-9F81-4FFA6996F551%40gmail.com.

Sam Stern

unread,
Mar 19, 2020, 9:21:11 AM3/19/20
to Firebase Google Group
Hey Shaiwal,

Where is your Flutter app running?  If you're running on an Android emulator then "localhost" won't resolve to your host computer.  Instead you need to use the special IP address 10.0.2.2.  Try changing "localhost:8080" to "10.0.2.2:8080" and see if that helps you connect.

- Sam

On Wed, Mar 18, 2020 at 2:04 PM Shaiwal Singh <sha...@gmail.com> wrote:
--

Shaiwal Singh

unread,
Mar 19, 2020, 1:32:06 PM3/19/20
to Firebase Google Group
Thanks Sam and Tomo,

I was running this on the iOS simulator that comes with MacOS.  Haven’t tried on an Android emulator yet.  Will try your suggestion too.  Though I had  tried it with 0.0.0.0 instead of localhost on iOS based on one of the stack overflow threads and had gotten the same results.

Will strip down my app to see if I can repro it and also see if I get a different behavior on Android.

Thanks for all your help.

Shaiwal

Reply all
Reply to author
Forward
0 new messages