fromDatastoreEntity<T extends Model> method

  1. @override
T? fromDatastoreEntity<T extends Model>(
  1. Entity? entity
)
override

Converts a ds.Entity to a Model instance.

Implementation

@override
T? fromDatastoreEntity<T extends Model>(ds.Entity? entity) {
  if (entity == null) {
    return null;
  }
  var key = fromDatastoreKey(entity.key);
  var kind = entity.key.elements.last.kind;
  var modelDescription = _kind2ModelDesc[kind];
  if (modelDescription == null) {
    throw StateError('Trying to deserialize entity of kind '
        '$kind, but no Model class available for it.');
  }

  try {
    return modelDescription.decodeEntity<T>(this, key, entity);
  } catch (error, stack) {
    throw StateError('Error while decoding entity ($error, $stack).');
  }
}