fromJson static method
Creates a new DataEntity from json
field
is used to determine the runtimeType of the DataEntity based on GridField.type
Implementation
static DataEntity fromJson({
required dynamic json,
required GridField field,
}) =>
switch (field.type) {
DataType.text => StringDataEntity(json),
DataType.dateTime => DateTimeDataEntity.fromJson(json),
DataType.date => DateDataEntity.fromJson(json),
DataType.integer => IntegerDataEntity(json),
DataType.checkbox => BooleanDataEntity(json),
DataType.singleSelect => EnumDataEntity(
value: json,
options: (field.schema['enum']?.cast<String>() as List<String>?)
?.toSet() ??
{},
),
DataType.crossReference => CrossReferenceDataEntity.fromJson(
jsonValue: json,
gridUri: field.schema['gridUri'] ?? '',
),
DataType.decimal => DecimalDataEntity(json),
DataType.attachment => AttachmentDataEntity.fromJson(json),
DataType.enumCollection => EnumCollectionDataEntity(
value:
((json ?? <String>[]).cast<String>() as List<String>).toSet(),
options: (field.schema['items']?['enum']?.cast<String>()
as List<String>?)
?.toSet() ??
{},
),
DataType.geolocation => GeolocationDataEntity.fromJson(json),
DataType.multiCrossReference => MultiCrossReferenceDataEntity.fromJson(
jsonValue: json,
gridUri: field.schema['items']?['gridUri'] ?? '',
),
DataType.createdBy => CreatedByDataEntity.fromJson(json),
DataType.user => UserDataEntity.fromJson(json),
DataType.currency => CurrencyDataEntity(
value: json,
currency: (field as CurrencyGridField).currency,
),
DataType.uri => UriDataEntity.fromJson(json),
DataType.email => EmailDataEntity(json),
DataType.phoneNumber => PhoneNumberDataEntity(json),
DataType.signature => SignatureDataEntity.fromJson(json),
DataType.createdAt => DateTimeDataEntity.fromJson(json),
DataType.lookUp => LookUpDataEntity.fromJson(
json,
lookedUpField: (field as LookUpGridField).lookedUpField,
),
DataType.reducedLookUp => ReducedLookUpDataEntity.fromJson(
json,
reducedField: (field as ReducedLookUpField).reducedField,
),
DataType.formula => FormulaDataEntity.fromJson(
json,
valueType: (field as FormulaField).valueType,
),
} as DataEntity;