capturePropertyFromProperty function
Helper for determining which property should be assigned to the value (used in response) property.
Implementation
CaptureProperty capturePropertyFromProperty(Property prop) {
final int id = prop.id ?? (throw StateError('Property ID cannot be null'));
final int type =
prop.type ?? (throw StateError('Property type cannot be null'));
dynamic value = <dynamic, dynamic>{};
switch (type) {
case CapturePropertyTypes.dataSource:
final DataSourceIos? ds = prop.dataSourceValue;
if (ds != null) {
value = DataSource(
id: ds.id ?? -1,
name: ds.name ?? '',
status: ds.status ?? -1,
flags: ds.flags ?? 0,
);
}
break;
case CapturePropertyTypes.array:
value = prop.arrayValue;
break;
case CapturePropertyTypes.string:
value = prop.stringValue;
break;
case CapturePropertyTypes.byte:
value = _toInt(prop.byteValue) ?? prop.byteValue;
break;
case CapturePropertyTypes.ulong:
value = _toInt(prop.longValue) ?? prop.longValue;
break;
case CapturePropertyTypes.object:
value = prop.objectValue;
break;
case CapturePropertyTypes.version:
value = prop.versionValue;
break;
case CapturePropertyTypes.Enum:
value = _toInt(prop.longValue) ?? prop.longValue;
break;
}
return CaptureProperty(id: id, type: type, value: value);
}