operator == method
Determines whether this Quantity is equal to another Object.
Two Quantity instances are considered equal if they are:
- The same instance (identical).
- Of the exact same runtime type (e.g., both
Length, not oneLengthand onePressure). - Have the same numerical value.
- Have the same unit.
This means 1.m is NOT equal to 100.cm according to ==, because their
units differ, even though their physical magnitudes are the same.
For magnitude comparison, use compareTo() or convert to a common unit first.
other: The object to compare against.
Returns true if the objects are equal based on the criteria above, false otherwise.
Implementation
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Quantity<T> &&
runtimeType == other.runtimeType &&
_value == other._value &&
_unit == other._unit;
}