dataTypeFromSchemaProperty function
Returns DataType that matching a certain schema schemaProperty
throws ArgumentError if DataType is not supported yet
Implementation
DataType dataTypeFromSchemaProperty({required dynamic schemaProperty}) {
final schemaType = schemaProperty['type'];
final format = schemaProperty['format'];
switch (schemaType) {
case 'string':
if (schemaProperty['enum'] != null) {
return DataType.selectionBox;
}
switch (format) {
case 'date-time':
return DataType.dateTime;
case 'date':
return DataType.date;
}
return DataType.text;
case 'integer':
return DataType.integer;
case 'boolean':
return DataType.checkbox;
}
throw ArgumentError(
'No according DataType found. Supported DataTypes are ${DataType.values}');
}