getFirstOrNull<TModel extends TRepositoryModel> method
Future<TModel?>
getFirstOrNull<TModel extends TRepositoryModel>({
- OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist,
- Query? query,
- bool seedOnly = false,
A safer version of getFirst that attempts to get the first instance of TModel
according to the query
, but returns null
if no instances exist.
Automatically applies 'limit': 1
to the query.
Implementation
Future<TModel?> getFirstOrNull<TModel extends TRepositoryModel>({
OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist,
Query? query,
bool seedOnly = false,
}) async {
final result = await super.get<TModel>(
policy: policy,
query: query?.copyWith(limit: 1),
seedOnly: seedOnly,
);
if (result.isEmpty) return null;
return result.first;
}