Wiki

Clone wiki

fling-units / AddingUnits

To add a new type of unit, perform the following: 1. Find the Interpreter for the measurement type associated with the unit in the /lib/src/measurements/ path (e.g. for a Mass unit, use MassInterpreter) 2. Define a new static const interpreter for the unit within the Interpreter class, with appropriate short name and multiplier (with respect to the SI unit):

static const _myUnits = MyMeasurementInterpreter._('mu', 0.5);
3. Add the interpreter to the MyMeasurementPrefix class:
PressureInterpreter get pascals => PressureInterpreter._pascals._withPrefix(_prefix);
4. Add the interpreter to the global namespace (outside of any class):
const myUnits = MyMeasurementInterpreter._myUnits;
5. Add the new unit to the NumExtension class in /lib/src/extensions/extension.dart:
/// Creates a MyUnit measurement.
MyMeasurement get myUnits => MyMeasurementInterpreter._myUnits(this);
6. Add a line in the NumExtender class in /lib/src/extensions/extender.dart:
/// Creates a MyUnit measurement.
MyMeasurement get myUnits => MyMeasurementInterpreter._myUnits._withPrefix(_prefix)(_value);
7. Verify your new unit in the unit tests 8. Document the new unit in the README.md file, under Supported Features

Updated