OnDartCondition class
A Condition implementation that evaluates the current Dart SDK version to determine whether an annotated component, configuration, or pod should be activated.
OnDartCondition works together with the ConditionalOnDart annotation to perform fine-grained control over component activation based on the Dart runtime version or version range.
This condition is particularly useful for maintaining compatibility across different Dart SDK releases, enabling or disabling features that rely on language changes or version-dependent APIs.
Behavior
- If the annotated element includes a ConditionalOnDart annotation:
- The
versionfield specifies the exact Dart version required. - The optional
rangefield defines a VersionRange that may include multiple acceptable versions. - The current runtime version is obtained from the RuntimeProvider.
- The condition passes if the running Dart version matches the specified version or falls within the specified range.
- Otherwise, the condition fails.
- The
- If no ConditionalOnDart annotation is found, the condition automatically passes.
Example
// Activate only if running on Dart 3.1.0
@ConditionalOnDart('3.1.0')
class Dart31Config {}
// Activate for any version from 3.0.0 to 3.5.0 (inclusive)
@ConditionalOnDart('3.0.0', VersionRange(min: Version(3, 0, 0), max: Version(3, 5, 0)))
class ModernFeatureSupport {}
Evaluation Flow
- When matches is invoked, the condition looks for a ConditionalOnDart annotation on the provided Annotation.
- If found, it retrieves the required version and version range.
- The current Dart version is extracted from the RuntimeProvider via the PackageNames.DART reference.
- The condition passes if:
- The runtime version exactly matches the declared version, or
- The runtime version is contained within the declared VersionRange.
- If no annotation is found or the runtime version cannot be determined, the condition passes by default.
Logging
- Logs key evaluation steps with clear semantic markers:
🧩when condition evaluation begins.✅for version matches or range inclusion.❌for version mismatches or absent Dart runtime data.
- When trace logging is enabled, logs include:
- Required version and range.
- Detected runtime version.
- Resolution path (exact match vs range match).
Related Components
- ConditionalOnDart: Annotation defining the required Dart SDK version.
- VersionRange: Specifies the allowed semantic version interval.
- RuntimeProvider: Supplies runtime package information for evaluation.
- ConditionalContext: Provides the environment and runtime context.
- Annotation: Represents the annotated element under evaluation.
- Implemented types
Constructors
- OnDartCondition()
-
A Condition implementation that evaluates the current Dart SDK version
to determine whether an annotated component, configuration, or pod
should be activated.
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
-
matches(
ConditionalContext context, Annotation annotation, Source source) → Future< bool> -
Evaluates the condition against the given ConditionalContext and
annotationfor the specified Source.override -
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