TypeEntity class final

Constructs a Entity representation by replacing occurrences of Object or dynamic in the baseType with corresponding values from subTypes. The replacements are applied sequentially based on their order in subTypes.

If no subTypes are provided, the method returns the baseType as-is (after trimming spaces).

Identity model (by design)

TypeEntity inherits Entity's integer-id identity model. Specifically:

  • The Entity.id of a TypeEntity is typeString.hashCode. Two TypeEntity instances with the same type-string are the same entity.
  • Equality is by Entity.id alone — _typeString is not compared in ==. This is consistent with Entity's contract and is what allows TypeEntity(MyService) to be used as a const-friendly registry key.

Caveats this contract imposes on callers:

  • String-hash collisions. Dart's String.hashCode is 32-bit. Two distinct type-strings can collide on hashCode. For a single-app DI registry with tens-to-low-hundreds of types, the collision probability is negligible; for a registry meant to scale to thousands of distinct types, this contract is not appropriate.

  • Type.toString() mangling under release. When baseType is a reified Type, this factory keys on Type.toString(). That string is not stable under dart2js --minify (the default for flutter build web --release) or under dart compile wasm — distinct types can map to the same mangled name. Two compiler-mangled names colliding means the corresponding registry slots merge silently.

    Mitigations:

    • Verify with a dart2js --minify / wasm CI build that the actual registered types of your app do not collide post-minification. The smoke_test/wasm_test/ harness covers until*; extend it to cover your app's specific type set.
    • Or supply an explicit caller-controlled Entity via DependencyMetadata.preemptivetypeEntity (constructed from a stable string token under your control) so the registry key does not depend on compiler output.

Examples:

// Example 1: Replacing multiple generic placeholders
final type1 = TypeEntity(Map<Object, Object>, [String, int]);
print(type1); // Output: Map<String,int>

// Example 2: Replacing `dynamic`
final type2 = TypeEntity('List<dynamic>', ['int']);
print(type2); // Output: List<int>

// Example 3: Handling non-generic types
final type3 = TypeEntity(int);
print(type3); // Output: int

// Example 4: More complex generics
final type4 = TypeEntity(Map<dynamic, List<Object>>, ['String', 'int']);
print(type4); // Output: Map<String,List<int>>
Inheritance

Constructors

TypeEntity(Object baseType, [List<Object> subTypes = const []])
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
id int
The value associated with this Entity instance.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

isDefault() bool
inherited
isNotDefault() bool
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
preferOverDefault(Entity other) Entity
Returns other if this is DefaultEntity, otherwise returns this.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited