preferredConstructors property
List of preferred constructors for autowiring.
Represents a constructor of a Dart class, including its parameters,
modifiers (const
, factory
), and the ability to create new instances.
This abstraction allows runtime instantiation of classes using metadata.
Example
class Person {
final String name;
final int age;
Person(this.name, this.age);
}
final constructor = reflector.reflectConstructor(Person);
final person = constructor.newInstance({'name': 'Alice', 'age': 30});
print(person.name); // Alice
This is especially useful in frameworks like dependency injection, serialization, and code generation where runtime construction is needed.
Implementation
final List<Constructor> preferredConstructors = [];