entityForType method Null safety

ManagedEntity entityForType(
  1. Type type

Returns a ManagedEntity for a Type.

type may be either a subclass of ManagedObject or a ManagedObject's table definition. For example, the following definition, you could retrieve its entity by passing MyModel or _MyModel as an argument to this method:

    class MyModel extends ManagedObject<_MyModel> implements _MyModel {}
    class _MyModel {
      int id;

If the type has no known ManagedEntity then a StateError is thrown. Use tryEntityForType to test if an entity exists.


ManagedEntity entityForType(Type type) {
  final entity = tryEntityForType(type);

  if (entity == null) {
    throw StateError(
        "No entity found for '$type. Did you forget to create a 'ManagedContext'?");

  return entity;