elementAt method
Returns the element of type T
at the specified index
.
Implementation
@override
T elementAt(int index) {
// TODO: this is identical to list[] - consider refactoring to combine them.
if (index < 0 || index >= length) {
throw RangeError.range(index, 0, length - 1);
}
var value = realmCore.resultsGetElementAt(this, _skipOffset + index);
if (value is RealmObjectHandle) {
late RealmObjectMetadata targetMetadata;
late Type type;
if (T == RealmValue) {
(type, targetMetadata) = realm.metadata.getByClassKey(realmCore.getClassKey(value));
} else {
targetMetadata = _metadata!;
type = T;
}
value = realm.createObject(type, value, targetMetadata);
}
if (T == RealmValue) {
value = RealmValue.from(value);
}
return value as T;
}