watchSingleOrNull method Null safety

  1. @override
Stream<T?> watchSingleOrNull()

Creates an auto-updating stream of this statement, similar to However, it is assumed that the query will only emit one result, so instead of returning a Stream<List<T>>, this returns a Stream<T?>. If the query emits more than one row at some point, an error will be emitted to the stream instead. If the query emits zero rows at some point, null will be added to the stream instead.

Be aware that this operation won't put a limit clause on this statement, if that's needed you would have to do use SimpleSelectStatement.limit:

Future<TodoEntry> loadMostImportant() {
  return (select(todos)
   ..orderBy([(t) =>
      OrderingTerm(expression: t.priority, mode: OrderingMode.desc)])

You should only use this method if you know the query won't have more than one row, for instance because you used limit(1) or you know the where clause will only allow one row.


Stream<T?> watchSingleOrNull() {
  return watch().transform(singleElementsOrNull());