Is there a way to use getX reactively for state management? Lets say my collection changes in Firestore and I want my UI to react automatically.
Also are you planning on adding persistence for state management just like hydrated_bloc exists for flutter_bloc? It would be great to continue from where user left off when restarting the app.
I think it depends on the Firebase. As long as they have any stream (ex. Firebase.onAuthStateChanged), then we can listen to it using .obs and ever combo.
Check this example https://github.com/jonataslaw/get/issues/215#issuecomment-641611736
Wait the firestore has nothing to do with auth right? It's the same principle tho I guess. You need to have a stream which you get from your snapshot and have your obs value listen to that stream.
final int _someInt = 5.obs;
final Stream<int> _yourStream;
YourController(this._yourStream);
@override
void onInit()
{
_someInt.bindStream(_yourStream);
ever(_someInt , (value) => print(_someInt));
}
I typed this here not in a IDE so it probably will have mistakes, but you get the point
Note: The injected value called value will be null, I think this is a bug right now. So just reference the obs directly
I think michael-ottink's answer perfectly answers your question.
Just use bind and join the firestore stream with a .obs variable.
Closing it.
checkout this method for the stream with firebase, link
Most helpful comment
Wait the firestore has nothing to do with auth right? It's the same principle tho I guess. You need to have a stream which you get from your snapshot and have your obs value listen to that stream.
I typed this here not in a IDE so it probably will have mistakes, but you get the point
Note: The injected value called value will be null, I think this is a bug right now. So just reference the obs directly