ConstructorDeclaration class abstract
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.
- Inheritance
-
- Object
- Declaration
- EntityDeclaration
- SourceDeclaration
- MemberDeclaration
- ConstructorDeclaration
Constructors
- ConstructorDeclaration()
-
Represents a constructor of a Dart class, including its parameters,
modifiers (
const
,factory
), and the ability to create new instances.const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getAnnotations(
) → List< AnnotationDeclaration> -
Returns all annotations applied to this declaration.
inherited
-
getDartType(
) → DartType? -
The analyzer DartType of the entity for enhanced type operations.
inherited
-
getDebugIdentifier(
) → String -
The debug identifier for the entity.
inherited
-
getElement(
) → Element? -
The analyzer element associated with this declaration.
inherited
-
getIsAbstract(
) → bool -
Returns
true
if this member is declaredabstract
.inherited -
getIsConst(
) → bool -
Whether this constructor is declared
const
. -
getIsFactory(
) → bool -
Whether this constructor is a
factory
. -
getIsPublic(
) → bool -
Checks if this declaration is a public declaration.
inherited
-
getIsStatic(
) → bool -
Returns
true
if this member is markedstatic
.inherited -
getIsSynthetic(
) → bool -
Checks if a declaration is a synthetic declaration.
inherited
-
getName(
) → String -
Gets the name of the declared element.
inherited
-
getParameters(
) → List< ParameterDeclaration> - Returns all parameters required by this constructor.
-
getParentClass(
) → LinkDeclaration? -
Returns the LinkDeclaration that owns this member.
inherited
-
getParentLibrary(
) → LibraryDeclaration -
Returns the LibraryDeclaration in which this declaration is defined.
inherited
-
getSourceLocation(
) → Uri? -
Returns the source code location (e.g., file path or URI) where this declaration is defined,
or
null
if not available in the current reflection context.inherited -
getType(
) → Type -
Gets the runtime type of the declared element.
inherited
-
hasAnalyzerSupport(
) → bool -
Returns true if this declaration has analyzer information available.
inherited
-
newInstance<
T> (Map< String, dynamic> arguments) → T - Creates a new instance of the declaring class using this constructor.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, Object> -
Returns a JSON representation of this entity.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited