convertTo method
Creates a new Pressure instance with the value converted to the targetUnit
.
This is useful for obtaining a new Pressure
object in a different unit
while preserving type safety and quantity semantics.
Example:
final p_bar = Pressure(1.5, PressureUnit.bar);
final p_psi = p_bar.convertTo(PressureUnit.psi);
print(p_psi); // Output: approx "21.7557 psi"
Implementation
@override
Pressure convertTo(PressureUnit targetUnit) {
if (targetUnit == unit) return this;
final newValue = getValue(targetUnit);
return Pressure(newValue, targetUnit);
}