ClassDeclaration constructor

const ClassDeclaration()

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

This interface combines both SourceDeclaration and TypeDeclaration, allowing it to be used both as a type descriptor and a declaration node.

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'});

Implementation

const ClassDeclaration();