ManagedDataModel constructor Null safety

  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]);


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

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

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