cachapa / firedart

A dart-native implementation of the Firebase Auth and Firestore SDKs
https://pub.dev/packages/firedart
Apache License 2.0
174 stars 62 forks source link

Streams are getting crossed? #53

Open esDotDev opened 3 years ago

esDotDev commented 3 years ago

Sorry, think I've found another bug :(

I have a structure like (books/BOOK_ID/pages): image

When using this stream inside a streamBuilder:

_pageStream = Firestore.instance.collection("users/shawn@test.com/books/$selectedBookId/pages").stream;

I get 3 calls to builder:

  1. First call has no data
  2. Second call is correct data (5 pages)
  3. Third call is a combination of data from 2 collections (5 pages + 7 books). The books stream was created on the previous route.

The 2nd and 3rd calls appear to happen in the same frame.

image

cachapa commented 3 years ago

Uh. I hate issues with streams because a lot of that happens in generated code from the protobuffs and is almost impossible to debug.

Though it could also just be bad stream initialization/reuse. To be fair I've only tested single streams so that case might have gone unnoticed.

I do not have much free time to work on firedart at the moment, so I can't be of much help. If this keeps being an issue for you I would recommend using one of the other firebase libraries.

esDotDev commented 3 years ago

There's nothing I know of that works on desktop :/ Do you know of any libs that run on windows/mac/linux other than this? We currently are using both fluttefire and firedart, with a shared abstraction layer, because we're trying to run all platforms.

For now we can get inventive with some client side filtering!

Sadly I think the decision would be more about abandoning Firestore completely and switching to mysql, which would kinda suck, both because of the lost work with firebase, but also the loss of realtime connection. Still have a couple of months to figure it out at least! Hopefully the client side filtering works ok.

cachapa commented 3 years ago

Desktop support was actually the reason why I started this project. I ended up going a different direction though, because I realised my particular use wasn't really suited for Firestore and would've drained my bank account.

If you're curious, I decided to go with CRDTs which sort of solve the problem of offline caching and conflict resolution. I implemented my own dart library here. There's also an example of real-time use in the form of a to-do app: tudo.

Sorry that I can't help more.

TimWhiting commented 3 years ago

@esDotDev https://github.com/fluttercommunity/firebase_dart_sdk This is a link to an sdk that is trying to implement a dart only sdk that confirms to the FlutterFire platform interfaces. My only problem with it is that it is currently on the older platform interfaces. Also, it might not have all the firestore features you want depending on your use case.

Personally I'm trying to use it, but you just have to figure out which versions of everything work together for mobile + desktop Alternatively you could try to use only that libraries pure dart implementation and not through the platform interface, though I don't know if web is supported by that implementation (except through the official platform interface).

esDotDev commented 3 years ago

Thanks a million Tim! The adventure continues :)

esDotDev commented 3 years ago

Personally I'm trying to use it, but you just have to figure out which versions of everything work together for mobile + desktop Alternatively you could try to use only that libraries pure dart implementation and not through the platform interface, though I don't know if web is supported by that implementation (except through the official platform interface).

Hey @TimWhiting, curious if you had any luck with the version solving here? We're in the same boat, trying to figure out how we can use the native sdk on mobile, but this other one on desktop, and not have version conflicts.

TimWhiting commented 3 years ago

@esDotDev Yeah, It's a personal project that I am just spending free time every once in a while doing. So I'm sort of waiting for the firebase_dart_sdk to support the ^2.*.* platform interfaces. (i.e. I don't have a project that I can show you with the correct version constraints).

Looking at cloud_firestore_dart it seems like you would need to use a version of cloud_firestore that was based off of the cloud_firestore_platform_interface: ^1.1.0 along with firebase_core: ^0.4.4+3. So, from there you would just need to use a version of firebase_auth that works with that version of firebase_core?

Starting with an empty project and this set of minimal dependencies:

dependencies:
  flutter:
    sdk: flutter
  firebase_core: any
  firebase_core_dart: any
  cloud_firestore: any
  cloud_firestore_dart: any
  firebase_auth: any
  firebase_auth_dart: any

pub upgrade resolved versions that work with each other (hopefully), I haven't actually tried it.

Here are the versions from the lock file:

dependencies:
  flutter:
    sdk: flutter
  firebase_core: 0.4.5
  firebase_core_dart: 0.0.1
  cloud_firestore: 0.13.7
  cloud_firestore_dart: 0.0.1
  firebase_auth: 0.16.1
  firebase_auth_dart: 0.0.1

To get anything newer you would have to depend on the github repository. I know that the maintainer has started working on support for version ^2.*.* platform interface for core, but auth and cloud_firestore haven't been fully updated.

Let me know if you get it working, & it would be great if the community could help contribute to keep that repository updated. I tried updating the auth a couple weeks ago, but it was more time than I had time for that day.

esDotDev commented 3 years ago

Woah, thanks a bunch! As part of our investigation we've also working on a desktop C++ plugin for Auth + Firestore, so we can just use one SDK across all platforms. So far it looks promising.