ManagedDataModel constructor Null safety

ManagedDataModel(
  1. List<Type> instanceTypes
)

Creates an instance of ManagedDataModel from a list of types that extend ManagedObject. It is preferable to use ManagedDataModel.fromCurrentMirrorSystem over this method.

To register a class as a managed object within this data model, you must include its type in the list. Example:

  new DataModel([User, Token, Post]);

Implementation

ManagedDataModel(List<Type> instanceTypes) {
  final runtimes = RuntimeContext.current.runtimes.iterable
      .whereType<ManagedEntityRuntime>()
      .toList();
  final expectedRuntimes = instanceTypes
      .map(
          (t) => runtimes.firstWhereOrNull((e) => e.entity.instanceType == t))
      .toList();

  final notFound = expectedRuntimes.where((e) => e == null).toList();
  if (notFound.isNotEmpty) {
    throw ManagedDataModelError(
        "Data model types were not found: ${notFound.map((e) => e!.entity.name).join(", ")}");
  }

  expectedRuntimes.forEach((runtime) {
    _entities[runtime!.entity.instanceType] = runtime.entity;
    _tableDefinitionToEntityMap[runtime.entity.tableDefinition] =
        runtime.entity;
  });
  expectedRuntimes.forEach((runtime) => runtime!.finalize(this));
}