onDataPoint method
On each data event from the data stream, the onDataPoint handler is
called. Implementations of this interface should handle how to save
or upload the dataPoint
.
Implementation
@override
Future<void> onDataPoint(DataPoint dataPoint) async {
final createdAt = DateTime.now().millisecondsSinceEpoch;
final createdBy = dataPoint.carpHeader.userId.toString();
final carpHeader = jsonEncode(dataPoint.carpHeader);
final carpBody = jsonEncode(dataPoint.carpBody);
final deploymentId = studyDeploymentId;
final sql =
"INSERT INTO $TABLE_NAME(created_at, created_by, deployment_id, carp_header, carp_body) VALUES('$createdAt', '$createdBy', '$deploymentId', '$carpHeader', '$carpBody')";
int? id = await database?.rawInsert(sql);
debug(
'$runtimeType - writing data point to SQLite - id: $id, type: ${dataPoint.carpHeader.dataFormat}');
}