how to sort stream from ObjectBox and difference .watch() vs .stream()

50 Views Asked by At

I am wondering hot to get a stream sorted.

This is my unsorted stream:

Stream<List<User> userStream = userBox.query()
  .watch(triggerImmediately: true).map((query) 
  => query.find();

Adding ..order() after query() or also after map((query) query adds in pre-compile errors.

Stream<List<User> userStream = userBox.query()
  ..order(User_.date)
  .watch(triggerImmediately: true).map((query) 
  => query.find();

Also - what is the difference of the above notation to

Query<User> query = userBox.query().build();
Stream<User stream = query.stream();
await stream.forEach((User user) => print(user));
query.close();

Has a stream() method be implemented in the meantime?

1

There are 1 best solutions below

0
On

Using

userBox.query().order(User_.date).watch(triggerImmediately: true)

should work.

stream() returns the results of the query once, watch() observes the associated Box and sends a Query whenever there are changes.

Source: ObjectBox Dart API reference