ConditionalOnDart class
An annotation that conditionally activates a Component, Pod, or configuration class based on the current Dart SDK version.
The ConditionalOnDart annotation allows JetLeaf to include or exclude annotated elements depending on the Dart version present at runtime or compile-time. This is particularly useful for maintaining compatibility across multiple SDK versions, leveraging version-specific features, or avoiding breaking changes.
Purpose
In JetLeaf applications, certain components or pods may only work with specific Dart versions. ConditionalOnDart provides a declarative mechanism to:
- Ensure compatibility with a target Dart SDK version or range.
- Conditionally register version-specific components.
- Prevent runtime errors or unsupported operations due to SDK mismatches.
Behavior
- version specifies the required Dart SDK version for the annotated
element. It can be a single version (e.g.,
'3.1.0') or interpreted by the range to match a broader version range. - range is an optional
VersionRangethat defines minimum, maximum, or compatible version intervals. Defaults to an unrestricted range. - The element is processed only if the current Dart SDK version satisfies the specified constraints.
Example
// Activate only for Dart SDK >=3.1.0
@ConditionalOnDart('3.1.0', VersionRange(min: '3.1.0'))
class ModernFeatureConfig {}
// Activate for a specific version
@ConditionalOnDart('3.0.5')
class LegacyFeatureConfig {}
Related Components
- ConditionalContext: Evaluates version constraints and determines conditional registration of pods or components.
VersionRange: Represents version constraints for evaluation.- Conditional: Base conditional annotation that ConditionalOnDart extends for declarative activation.
- Inheritance
-
- Object
- WhenConditional
- ConditionalOnDart
- Annotations
-
- @Conditional([OnDartCondition()])
- @Target.new({TargetKind.classType, TargetKind.method})
Constructors
- ConditionalOnDart(String version, [VersionRange range = const VersionRange()])
-
An annotation that conditionally activates a Component, Pod, or
configuration class based on the current Dart SDK version.
const
Properties
- annotationType → Type
-
Returns the annotation _type of this annotation.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- range → VersionRange
-
Optional
VersionRangeused by JetLeaf to evaluate version constraints.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- version → String
-
The Dart SDK version required for the annotated element to be processed.
final
Methods
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString. -
equals(
Object other) → bool -
Checks whether the given object is logically equivalent to this annotation.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String - Returns a string representation of this annotation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited