getSingleOrNull method

  1. @override
Future<$ActiveDataclass?> getSingleOrNull({
  1. bool distinct = true,
})
override

Executes this statement, like get, but only returns one value. If the result too many values, this method will throw. If no row is returned, null will be returned instead.

See also: getSingle, which can be used if the query will always evaluate to exactly one row.

The distinct parameter (enabled by default) controls whether to generate a SELECT DISTINCT query, removing duplicates from the result.

Implementation

@override
Future<$ActiveDataclass?> getSingleOrNull({bool distinct = true}) async {
  final list = await get(distinct: distinct);
  if (list.isEmpty) {
    return null;
  } else {
    return list.single;
  }
}