valueForDynamicField method

dynamic valueForDynamicField(
  1. String fieldName,
  2. FieldElement element
)
inherited

Return the actual value for fields of an element that could be one of any primitive

Implementation

dynamic valueForDynamicField(String fieldName, FieldElement element) {
  final dynamicValue = objectForField(element)?.getField(fieldName);
  if (dynamicValue == null || dynamicValue.isNull) {
    return null;
  }

  final checker = SharedChecker(dynamicValue.type!);
  if (checker.isEnum || !checker.isSerializable) {
    throw Exception('$fieldName on ${element.name} must be a primitive');
  }

  if (checker.isBool) return dynamicValue.toBoolValue();
  if (checker.isDouble) return dynamicValue.toDoubleValue();
  if (checker.isInt) return dynamicValue.toIntValue();
  if (checker.isString) return '"${dynamicValue.toStringValue()}"';
  if (checker.isList) return dynamicValue.toListValue();
  if (checker.isSet) return dynamicValue.toSetValue();
  if (checker.isMap) return dynamicValue.toMapValue();
}