getRecords method

Future<List<Record>> getRecords({
  1. required List<MetricType> ofTypes,
  2. required DateTime from,
  3. required DateTime to,
  4. StatisticsFilter? filter,
})

Retrieves all records based on the specified configuration.

ofTypes - Array of metric types to retrieve (e.g., heart rate, steps, sleep)

from - Start datetime for the data range (inclusive)

to - End datetime for the data range (exclusive)

filter - Optional filter to apply to the results (can filter by provider, etc.)

Implementation

Future<List<Record>> getRecords({
  required List<MetricType> ofTypes,
  required DateTime from,
  required DateTime to,
  StatisticsFilter? filter,
}) async {
  final result = await NativeSDKBridgeV3.getRecords(
    connectionId: connectionId,
    ofTypes: ofTypes.map((e) => e.toJson()).toList(),
    from: from.toUtc().toIso8601String(),
    to: to.toUtc().toIso8601String(),
    filter: filter != null ? jsonEncode(filter.toJson()) : null,
  );
  // log("Records result: $result");

  ExceptionHandler.checkException(result);

  final object = jsonDecode(result) as List;
  List<Record> records = object.map((e) => Record.fromJson(e)).toList();

  return records;
}