queryLocations static method
- LocationQuery query
Queries stored locations with filtering and pagination.
Implementation
static Future<List<Location>> queryLocations(LocationQuery query) async {
// Pull only what is needed based on limit/offset to reduce memory use
final limit = query.limit;
final offset = query.offset;
final fetchLimit = limit != null ? limit + offset : null;
final fetched = await getLocations(limit: fetchLimit);
final sliced = offset >= fetched.length
? <Location>[]
: (fetchLimit == null
? fetched.sublist(offset)
: fetched.sublist(offset, offset + (limit ?? 0)));
final adjustedQuery = LocationQuery(
from: query.from,
to: query.to,
minAccuracy: query.minAccuracy,
maxAccuracy: query.maxAccuracy,
isMoving: query.isMoving,
bounds: query.bounds,
sortOrder: query.sortOrder,
offset: 0,
limit: null,
);
return adjustedQuery.apply(sliced);
}