Turn Live Query Results Into Streams

Is there a way I can turn Live query results into streams in flutter? I need to create a method that returns a Stream of Posts…

Stream<List<Post>> fetchPosts () async* {
   final QueryBuilder<ParseObject> query = QueryBuilder<ParseObject>(ParseObject('Post'));
   final Subscription<ParseObject> subscription = await _liveQuery.client.subscribe(query);

      subscription.on(LiveQueryEvent.create, (value)  { 
         // return Stream<List<Post>> here..

Take a look in the last example in this link: Creating streams in Dart | Dart

It shows an example using a StreamController. I think that something like this should work.

Thanks very much. l did managed to return a Stream of Posts. But is there an elegant way of combining Live Query Event types such as create, update, delete, enter and exit into one? A method l could perhaps call and get a list of Parse objects that increment when a new object matching the query is added or decrement when an object is removed??

I am not sure if there’s a specific function in the flutter sdk to do that but it could be a great addition.

1 Like