copy method

  1. @override
FutureOr<O?> copy(
  1. O obj
)
override

Creates a copy of obj.

  • The default implementation uses JSON to copy the internal data.

Implementation

@override
FutureOr<O?> copy(O obj) {
  final reflection = this.reflection;

  final noReferenceField = fieldsWithTypeEntityOrReference(obj).isEmpty;
  if (noReferenceField) {
    var fields = reflection.getJsonFieldsVisibleValues(obj);
    var copy = reflection.createFromMapSync(fields);
    return copy;
  }

  var json = reflection.toJson(obj);
  return reflection.fromJson(json);
}