Skip to content

Migration Guide 2.x to 3.x

Bruce Santier edited this page Feb 18, 2025 · 2 revisions

Version 3.x of Fling Units introduces several breaking changes in order to improve the library's interface. This guide is geared towards helping to update your 2.x compatible code so you can take advantage of the improvements in 3.x.

Dimensions

Dimensions have been formalized, and are now used more correctly in the code.

If you previously referred to a dimension as a parameterized type, you will likely need to switch to using the corresponding Measurement instead. This also applies to the const constructors for measurements.

2.x 3.x Notes
<Distance>[] <DistanceMeasurement> or <Measurement<Distance>> Prefer the <X>Measurement types to have a broader interface

In general, prefer the specific type (e.g. DistanceMeasurement), as you'll get a broader interface.

2.x 3.x
const Distance(5.0, inches) const DistanceMeasurement(5.0, inches)

If you previously referred to a dimension directly, odds are you will need to refer instead to a unit or a global function. This affects the sum function.

2.x 3.x
Distance.sum(myList) sum(myList)

The special constructors zero, infinite, negativeInfinite, and nan can just be replaced with a reference to the equivalent double value.

Zero:

2.x 3.x Notes
Distance.zero() 0.meters Use the unit you want as the measurement's default unit
Distance.infinite() double.infinity.meters Also works for any other special value of double, e.g. nan

Precision

Instead of forcing you to pass in precision as an instance of a class, the public APIs just accept ints. If you used withPrecisionOf() then you just need to switch to withPrecision().

2.x 3.x
miles(1, precision: Precision(3)) miles(1, precision: 3)
1.miles.withPrecisionOf(3) 1.miles.withPrecision(3)

Area

The Area class has been removed, and its features are instead globally accessible. If you made use of of, replace it with with by.

2.x 3.x
Area.square(feet) square(feet)
Area.of(1.feet, 1.feet) 1.feet.by(1.feet)

Volume

The Volume class has been removed, and its features are instead globally accessible.

Derived Units

The per function has been replaced with a convenience getter that allows easy construction of derived units. Instead, use over. If you used by, you can continue to do so.

2.x 3.x
2.miles.per(1.hours) 2.miles.over(1.hours)

The DerivedMeasurement class has been removed. Use the convenience functions per and by to create measurements instead. If you used DerivedMeasurement's zero, infinite, negativeInfinite, or nan methods, instead instantiate the derived units with the corresponding double value.

2.x 3.x
DerivedMeasurement.divide(2.miles, 1.hours) 2.miles.over(1.hours)
DerivedMeasurement.multiply(2.meters, 3.meters) 2.meters.by(3.meters)
DerivedMeasurement<Distance, Time>.zero() 0.meters/per.second
DerivedMeasurement<Distance, Time>.infinite() double.infinity.meters.per.second

The DerivedMeasurementInterpreter class is no longer needed. You should instead create derived units with per and dot.

2.x 3.x Notes
DerivedMeasurementInterpreter(feet, minutes, true, MeasurementPrefix.unit(), "feet per minute") feet.per.minute.withName("feet per minute") Ratio of base units
DerivedMeasurementInterpreter(feet, minutes, false, MeasurementPrefix.unit(), "foot minutes") feet.dot.minutes.withName("foot minutes") Product of base units

Measurements

The withDefaultUnit method has been renamed to butAs.

2.x 3.x
1.meters.withDefaultUnit(yards) 1.meters.butAs(yards)
Clone this wiki locally