Comparison enum

Represents the result of a comparison operation between two values.

This enum provides a type-safe way to work with comparison results, replacing magic numbers (-1, 0, 1) with meaningful enum cases.

Use this instead of raw integer comparisons for better readability and type safety.

Example:

final comparison = 'a'.compareWith('b');
if (comparison == Comparison.less) {
  print('First is less than second');
}
Inheritance
Available extensions

Values

less → const Comparison

Indicates the first value is less than the second.

equal → const Comparison

Indicates the first value is equal to the second.

greater → const Comparison

Indicates the first value is greater than the second.

Properties

hashCode int
The hash code for this object.
no setterinherited
index int
A numeric identifier for the enumerated value.
no setterinherited
name String

Available on Enum, provided by the EnumName extension

The name of the enum value.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

asInt() int
Converts this comparison result to its integer representation.
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

Constants

values → const List<Comparison>
A constant List of the values in this enum, in order of their declaration.