copy method

Future<bool> copy(
  1. dynamic from,
  2. dynamic to
)

Implementation

Future<bool> copy(dynamic from, dynamic to) async {
  var fromElement = getElement(from);
  if (fromElement == null) return false;

  // get json
  var json = Json.encode(Json.copy(fromElement, withValues: true));

  // get index
  int? index = isNumeric(to) ? toInt(to) : null;

  // before specific object?
  if (index == null) {
    var toElement = getElement(to);
    if (toElement != null) index = data?.indexOf(toElement);
  }

  // insert the values
  return await insert(json, index);
}