convertToPrimitiveValue method

  1. @override
dynamic convertToPrimitiveValue(
  1. dynamic value
)
override

Converts a value from a more complex value into a primitive value according to this instance's definition.

This method takes a Dart representation of a value and converts it to something that can be used elsewhere (e.g. an HTTP body or database query). How this value is computed depends on this instance's definition.

Implementation

@override
dynamic convertToPrimitiveValue(dynamic value) {
  if (value == null) {
    return null;
  }

  if (type!.kind == ManagedPropertyType.datetime && value is DateTime) {
    return value.toIso8601String();
  } else if (isEnumeratedValue) {
    // todo: optimize?
    return value.toString().split(".").last;
  } else if (type!.kind == ManagedPropertyType.document &&
      value is Document) {
    return value.data;
  }

  return value;
}