Skip to content

Data

Base class of all collected data, such as a location or a heart rate.

A probe or user task produces a Data object, which is wrapped in a Measurement with a timestamp and uploaded. This base class holds no values itself; subclasses add the fields.

Key points:

  • The data type (dataType) is derived from jsonType. By default this is dk.cachet.carp.<classname in lowercase>, e.g. dk.cachet.carp.geolocation for Geolocation.
  • Each subclass must be registered in FromJsonFactory to be deserialized.
  • Override equivalentTo to let triggers react to specific data values.

See also SensorData, InputData and the data type names in CarpDataTypes.

Inheritance
Implementers
Annotations

Constructors

Data.fromJson

Data.fromJson(
  1. Map<String, dynamic> json
)

Data

Data()

Properties

dataType

  1. @JsonKey(includeFromJson: false, includeToJson: false)
DataType get dataType

The type of this data as a DataType.

fromJsonFunction

Function get fromJsonFunction
override

The function which can convert a JSON string to an object of this type.

jsonType

String get jsonType
override

Return the __type to be used for JSON serialization of this class. Default is runtimeType. Only specify this if you need another type.

recordId

  1. @JsonKey(includeFromJson: false, includeToJson: false)
String? get recordId

Stable identifier of the source record, if available; null by default.

Subclasses whose data comes from a store with record ids (e.g., health data) can return it, e.g. to avoid duplicates. Not serialized.

Methods

equivalentTo

bool equivalentTo(
  1. Data other
)

Is this data equivalent to other?

This is a custom 'soft' equal (==) operator used to compare two data objects. Used in triggering when some data is collected. Returns false in this base class; override in subclasses to provide custom equivalence checking.

toJson

Map<String, dynamic> toJson()
override

Return a JSON encoding of this object.