Condition class final
A conditional expression that can be evaluated at runtime.
Conditions are used to make dynamic decisions in the application based on the current state or user input. They can be used for:
- Navigation guards
- Content visibility
- Feature flags
- A/B testing
Example CMS schema:
export const condition = defineType({
name: 'condition',
fields: [
{
name: 'configuration',
type: 'reference',
to: [{type: 'condition.config'}],
},
],
});
Example usage:
final condition = Condition(
configuration: UserRoleCondition(
allowedRoles: ['admin', 'editor'],
),
);
// Evaluate the condition
final result = await condition.execute(context);
if (result == null) {
// Condition passed
} else {
// Condition failed with error message
print('Access denied: $result');
}
- Annotations
-
- @JsonSerializable()
Constructors
- Condition.new({ConditionConfiguration? configuration})
- Creates a new condition with the given configuration.
-
Condition.fromJson(Map<
String, dynamic> json) -
Creates a condition from a JSON object.
factory
Properties
- configuration → ConditionConfiguration?
-
The configuration that defines the condition's logic.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
execute(
BuildContext context) → Future< String?> - Evaluates the condition in the current context.
-
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