read static method

Future<List<HealthData>?>? read(
  1. DataType type, {
  2. DateTime? dateFrom,
  3. DateTime? dateTo,
  4. int? limit,
})

It's not advised to call await HealthKit.read(dataType) without any extra parameters. This can lead to FAILED BINDER TRANSACTION on Android devices because of the data batch size being too large.

Implementation

static Future<List<HealthData>?>? read(
  DataType type, {
  DateTime? dateFrom,
  DateTime? dateTo,
  int? limit,
}) async {
  return await _channel
      .invokeListMethod('read', {
        "type": _dataTypeToString(type),
        "date_from": dateFrom?.millisecondsSinceEpoch ?? 1,
        "date_to": (dateTo ?? DateTime.now()).millisecondsSinceEpoch,
        "limit": limit,
      })
      .then(
        (response) =>
            response?.map((item) => HealthData.fromJson(item)).toList(),
      )
      .catchError(
        (_) => throw UnsupportedException(type),
        test: (e) {
          if (e is PlatformException) return e.code == 'unsupported';
          return false;
        },
      );
}