getAllSortedByFilter method

Future<List<Log>> getAllSortedByFilter({
  1. required List<Filter> filters,
})

Fetch all Logs which match the given filters and sorts them by dataLogType

Implementation

Future<List<Log>> getAllSortedByFilter(
    {required List<Filter> filters}) async {
  //creating finder
  final finder = Finder(
      filter: Filter.and(filters),
      sortOrders: [SortOrder(DBConstants.FIELD_DATA_LOG_TYPE)]);

  final recordSnapshots = await (_flogsStore.find(
    await _db,
    finder: finder,
  ));

  // Making a List<Log> out of List<RecordSnapshot>
  return recordSnapshots.map((snapshot) {
    final log = Log.fromJson(snapshot.value);
    // An ID is a key of a record from the database.
    log.id = snapshot.key;
    return log;
  }).toList();
}