Class<T> class
abstract
Provides reflective access to Dart class types and their metadata.
This interface enables runtime inspection and manipulation of class:
- Type information and hierarchy
- Constructors and instantiation
- Methods and fields
- Annotations and metadata
- Generic type parameters
{@template class_interface_features}
Key Features
- Type-safe reflection operations
- Generic type parameter support
- Class hierarchy navigation
- Instance creation
- Member inspection
- Annotation access
Implementation Notes
Concrete implementations typically wrap platform-specific reflection objects while providing this uniform interface.
Example Usage
// Get class metadata
final userClass = Class.forType<User>();
// Create instances
final user = userClass.newInstance({'name': 'Alice', 'age': 30});
// Inspect fields
final nameField = userClass.getField('name');
print(nameField?.get(user)); // 'Alice'
// Check type hierarchy
if (userClass.isSubclassOf(Class.forType<Person>())) {
print('User is a Person subclass');
}
Type Parameters:
T
: The class type being reflected {@endtemplate}
- Inheritance
-
- Object
- PermissionManager
- Source
- Class
- Implemented types
- Annotations
-
- @Generic(Class)
Constructors
- Class([ProtectionDomain? domain, String? package])
-
Represents a reflected Dart class and all of its metadata, including
fields, methods, constructors, superclasses, mixins, interfaces, and
declaration-level modifiers (abstract, sealed, etc.).
factory
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
-
annotationMatches<
A> (Annotation annotation) → bool -
inherited
-
checkAccess(
String operation, DomainPermission permission) → void -
Verifies access permissions before performing sensitive operations.
inherited
-
componentType<
C> () → Class< C> ? - Gets the component type for collection-like generic classes.
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode
, andtoString
.inherited -
getAllAnnotations(
) → List< Annotation> - Returns:
-
getAllDeclaredInterfaceArguments(
) → List< Class> - Gets generic arguments from all declared interfaces.
-
getAllDeclaredInterfaces(
) → List< Class> - Gets all directly declared interfaces (non-transitive).
-
getAllDeclaredMixins(
) → List< Class> - Gets all directly declared mixins (non-transitive).
-
getAllDeclaredMixinsArguments(
) → List< Class> - Gets generic arguments from all declared mixins.
-
getAllDirectAnnotations(
) → List< Annotation> -
Gets all annotations applied to this element.
inherited
-
getAllInterfaceArguments(
) → List< Class> - Gets generic arguments from all implemented interfaces.
-
getAllInterfaces(
) → List< Class> - Gets all interfaces directly implemented by this class.
-
getAllMethodsInHierarchy(
) → List< Method> - Gets all methods declared in this class and its hierarchy.
-
getAllMixins(
) → List< Class> - Gets all mixins applied to this class.
-
getAllMixinsArguments(
) → List< Class> - Gets generic arguments from all applied mixins.
-
getAnnotation<
A> () → A? - Gets a single annotation by type, if present.
-
getAnnotations<
A> () → List< A> - Gets all annotations of a specific type.
-
getBestConstructor(
List< Class> paramTypes) → Constructor? - Gets the best constructor for the given parameter types.
-
getCanonicalName(
) → String - Gets the canonical name with complete generic type information.
-
getConstructor(
String name) → Constructor? - Gets a constructor by its declared name.
-
getConstructorBySignature(
List< Class> paramTypes) → Constructor? - Gets a constructor by its parameter types.
-
getConstructors(
) → List< Constructor> - Gets all constructors declared in this class.
-
getDeclaration(
) → Declaration -
Gets the type declaration metadata for this class.
override
-
getDeclaredInterface<
I> () → Class< I> ? - Gets a specific declared interface (non-transitive).
-
getDeclaredInterfaceArguments<
I> () → List< Class> - Gets generic arguments from a specific declared interface.
-
getDeclaredInterfaces<
I> () → List< Class< I> > - Gets declared interfaces of specific type (non-transitive).
-
getDeclaredMembers(
) → List< Object> - Gets all members (fields, methods, constructors) declared in this class.
-
getDeclaredMixin<
I> () → Class< I> ? - Gets a specific declared mixin (non-transitive).
-
getDeclaredMixins<
I> () → List< Class< I> > - Gets declared mixins of specific type (non-transitive).
-
getDeclaredMixinsArguments<
M> () → List< Class> - Gets generic arguments from a specific declared mixin.
-
getDeclaredSuperClass(
) → Class? - Gets the declared superclass without generic resolution.
-
getDefaultConstructor(
) → Constructor? - Gets the default unnamed constructor for this class.
-
getDirectAnnotation<
A> () → A? -
Gets a single annotation by type, if present.
inherited
-
getDirectAnnotations<
A> () → List< A> -
Gets all annotations of a specific type.
inherited
-
getEnumValues(
) → List< Field> - Gets all enum values if this is an enum class.
-
getField(
String name) → Field? -
Gets a field by its name.
inherited
-
getFieldCount(
) → int - Gets the total number of fields.
-
getFields(
) → List< Field> -
Gets all fields declared in this class.
inherited
-
getInterface<
I> () → Class< I> ? - Gets a specific implemented interface.
-
getInterfaceArguments<
I> () → List< Class> - Gets generic arguments from a specific implemented interface.
-
getInterfaces<
I> () → List< Class< I> > - Gets implemented interfaces of specific type.
-
getMethod(
String name) → Method? - Gets a method by its name.
-
getMethodBySignature(
String name, List< Class> parameterTypes) → Method? - Gets a method by its name and parameter types.
-
getMethods(
) → List< Method> - Gets all methods declared in this class.
-
getMethodsByName(
String name) → List< Method> - Gets all methods with a specific name.
-
getMixin<
I> () → Class< I> ? - Gets a specific mixin applied to this class.
-
getMixins<
I> () → List< Class< I> > - Gets mixins of specific type applied to this class.
-
getMixinsArguments<
M> () → List< Class> - Gets generic arguments from a specific applied mixin.
-
getName(
) → String -
Gets the declared name of the source.
inherited
-
getNamedField(
String name) → Field? - Gets a named field by name.
-
getNamedFieldCount(
) → int - Gets the count of named fields.
-
getNamedFields(
) → Map< String, Field> - Gets all named fields as a name-to-field map.
-
getNoArgConstructor(
[bool acceptWhenAllParametersAreOptional = false]) → Constructor? - Retrieves the no-argument constructor of this Constructor instance, if available.
-
getOriginal(
) → Type - Gets the underlying type requested by Class
-
getOverriddenMethods(
) → List< Method> - Gets all methods that are overridden in this class.
-
getPackage(
) → Package? - Gets the package metadata for this class.
-
getPackageUri(
) → String - Gets the package URI where this class is defined.
-
getPositionalField(
int index) → Field? - Gets a positional field by index.
-
getPositionalFieldCount(
) → int - Gets the count of positional fields.
-
getPositionalFields(
) → List< Field> - Gets all positional fields in declaration order.
-
getProtectionDomain(
) → ProtectionDomain -
Gets the protection domain governing access to this element.
inherited
-
getQualifiedName(
) → String -
Represents an object that can provide a fully qualified name.
inherited
-
getSignature(
) → String -
Gets the executable signature as a string.
inherited
-
getSimpleName(
) → String - Gets the simple class name without package or generic information.
-
getSubClass<
S> () → Class< S> ? - Gets a specific direct subclass by type.
-
getSubClasses(
) → List< Class> - Gets all direct subclasses of this class.
-
getSuperClass<
S> () → Class< S> ? - Gets the direct superclass with proper generic typing.
-
getSuperClassArguments(
) → List< Class> - Gets the generic arguments from the superclass declaration.
-
getType(
) → Type - Gets the runtime type of this generic class.
-
getTypeDeclaration(
) → TypeDeclaration - Gets the type declaration of this class.
-
getTypeParameters(
) → List< Class> - Gets all generic type parameters of this class.
-
hasAnnotation<
A> () → bool - Checks if this element has a specific annotation.
-
hasDirectAnnotation<
A> () → bool -
Checks if this element has a specific annotation.
inherited
-
hasGenerics(
) → bool - Checks if this class has generic type parameters.
-
hasNamedFields(
) → bool - Checks if this record has any named fields.
-
hasPositionalFields(
) → bool - Checks if this record has any positional fields.
-
isAbstract(
) → bool - Checks if this class is abstract.
-
isArray(
) → bool - Checks if this class represents an array type.
-
isAssignableFrom(
Class other) → bool - Checks type assignability from another class.
-
isAssignableTo(
Class other) → bool - Checks if this type is assignable to another type.
-
isBase(
) → bool - Checks if this class is a base class (can be extended but not implemented).
-
isCanonical(
) → bool - Checks if the display name matches the canonical name.
-
isClass(
) → bool - Checks if this class represents a standard class type.
-
isEnum(
) → bool - Checks if this class is an enum declaration.
-
isExtension(
) → bool - Checks if this class represents an extension.
-
isFinal(
) → bool - Checks if this class is final (cannot be extended).
-
isInstance(
Object? obj) → bool - Checks if an object is an instance of this class.
-
isInterface(
) → bool - Checks if this class is an interface (abstract with no concrete members).
-
isInvokable(
) → bool - Checks if this class is invokable.
-
isKeyValuePaired(
) → bool - Checks if this class represents a key-value pair type.
-
isMixin(
) → bool - Checks if this class is a mixin declaration.
-
isPrimitive(
) → bool - Checks if this class represents a primitive type.
-
isPublic(
) → bool -
Checks if this element is public.
inherited
-
isRecord(
) → bool - Checks if this class represents a record type.
-
isSealed(
) → bool - Checks if this class is sealed (exhaustive pattern matching).
-
isSubclassOf(
Class other) → bool - Checks if this class directly extends another class.
-
isTypedef(
) → bool - Checks if this class represents a typedef.
-
isTypeVariable(
) → bool - Checks if this class represents a type variable.
-
keyType<
K> () → Class< K> ? - Gets the key type for map-like generic classes.
-
newInstance(
[Map< String, dynamic> ? arguments, String? constructorName]) → T - Creates an instance using the default constructor.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
declared<
C> (TypeDeclaration declaration, ProtectionDomain domain) → Class< C> - Creates a Class instance from type declaration metadata.
-
forName<
C> (String name, [ProtectionDomain? domain, String? package]) → Class< C> - Creates a Class instance for a runtime type name.
-
forObject(
Object obj, [ProtectionDomain? domain, String? package]) → Class< Object> - Creates a Class instance for an object's runtime type.
-
forType<
C> (C type, [ProtectionDomain? domain, String? package]) → Class< C> - Creates a Class instance for a runtime type.
-
fromQualifiedName<
C> (String qualifiedName, [ProtectionDomain? domain]) → Class< C> - Creates a Class instance from a fully qualified name.
-
of<
F> ([ProtectionDomain? domain, String? package]) → Class< F> - Creates a Class instance for type F.