ClassDeclaration class abstract final

Represents a reflected Dart class and all of its metadata, including fields, methods, constructors, superclasses, mixins, interfaces, and declaration-level modifiers (abstract, sealed, etc.).

Use this class to introspect:

  • Class members: fields, methods, constructors
  • Generic type parameters
  • Supertype, mixins, and implemented interfaces
  • Modifiers like abstract, sealed, base, etc.
  • Runtime instantiation via newInstance()

Example

final type = reflector.reflectType(MyService).asClassType();
print('Class: ${type?.getName()}');

for (final method in type!.getMethods()) {
  print('Method: ${method.getName()}');
}

final instance = type.newInstance({'message': 'Hello'});
Inheritance
Implemented types
Mixed-in types

Properties

hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
inherited
getAnnotations() List<AnnotationDeclaration>
Returns all annotations applied to this declaration in source code.
inherited
getConstructors() List<ConstructorDeclaration>
Returns all constructors declared in this class.
getDebugIdentifier() String
Returns the stable debug identifier for this entity.
override
getField(String fieldName) FieldDeclaration?
Returns a field by its fieldName, or null if no field with that name exists.
getFields() List<FieldDeclaration>
Returns all fields declared in this class, excluding inherited fields.
getHasInterfaces() bool
Returns true if this class implements one or more interfaces.
getInstanceFields() List<FieldDeclaration>
Returns all instance fields declared in this class or mixin.
getInstanceMethods() List<MethodDeclaration>
Returns all instance methods declared in this class or mixin.
getInterfaces() List<LinkDeclaration>
Returns the list of interfaces this type implements.
getIsAbstract() bool
Returns true if this class is marked abstract.
getIsBase() bool
Returns true if this class is declared as base.
getIsFinal() bool
Returns true if this class is declared as final.
getIsInterface() bool
Returns true if this class is declared as an interface.
getIsMixin() bool
Returns true if this declaration is a mixin or a mixin application.
getIsPublic() bool
Indicates whether this declaration is publicly visible.
inherited
getIsRecord() bool
Returns true if this class represents a record class.
getIsSealed() bool
Returns true if this class is declared as sealed.
getIsSynthetic() bool
Indicates whether this declaration is synthetic.
inherited
getKind() TypeKind
Returns the TypeKind describing what kind of type this declaration represents.
getLibrary() LibraryDeclaration
Returns the LibraryDeclaration in which this class is declared.
getMembers() List<MemberDeclaration>
Returns all members declared in this class, including fields, methods, and constructors.
getMethod(String methodName) MethodDeclaration?
Returns a method by its methodName, or null if no method with that name exists.
getMethods() List<MethodDeclaration>
Returns all methods declared in this class, excluding inherited methods.
getMixins() List<LinkDeclaration>
Returns the list of mixin identities that are applied to this type.
getName() String
Returns the simple (unqualified) name of this declaration.
inherited
getPackageUri() String
Returns the package URI in which this class is declared.
getQualifiedName() String
Returns the fully-qualified identifier for this object.
inherited
getSimpleName() String
Returns the simple (unqualified) name of this class.
getSourceLocation() Uri?
Returns the URI pointing to the source location where this declaration is defined.
inherited
getStaticFields() List<FieldDeclaration>
Returns all static fields declared in this class or mixin.
getStaticMethods() List<MethodDeclaration>
Returns all static methods declared in this class or mixin.
getSuperClass() LinkDeclaration?
Returns the direct superclass of this type.
getType() Type
Returns the Dart Type represented by this declaration.
inherited
getTypeArguments() List<LinkDeclaration>
Returns the list of type arguments for generic types.
hasField(String fieldName) bool
Checks if this class or mixin declares a field with the given fieldName.
hasMethod(String methodName) bool
Checks if this class or mixin declares a method with the given methodName.
isGeneric() bool
Returns true if this class declares generic type parameters.
newInstance(Map<String, dynamic> arguments) → dynamic
Instantiates this class using the default (unnamed) constructor.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, Object>
Serializes this declaration into a JSON-compatible map.
override
toString() String
A string representation of this object.
inherited

Operators

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