Volume constructor

Volume({
  1. int significantFigures = 10,
  2. bool removeTrailingZeros = true,
  3. dynamic name,
})

Class for volume conversions, e.g. if you want to convert 1 liter in US Gallons:

var volume = Volume(removeTrailingZeros: false);
volume.convert(Unit(VOLUME.liters, value: 1));
print(VOLUME.us_gallons);

Implementation

Volume({this.significantFigures = 10, this.removeTrailingZeros = true, name}) {
  size = VOLUME.values.length;
  this.name = name ?? PROPERTY.volume;
  for (VOLUME val in VOLUME.values) {
    unitList.add(Unit(val, symbol: mapSymbols[val]));
  }
  unitConversion = Node(
    name: VOLUME.cubicMeters,
    leafNodes: [
      Node(coefficientProduct: 1e-3, name: VOLUME.liters, leafNodes: [
        Node(
          coefficientProduct: 4.54609,
          name: VOLUME.imperialGallons,
        ),
        Node(
          coefficientProduct: 3.785411784,
          name: VOLUME.usGallons,
        ),
        Node(
          coefficientProduct: 0.56826125,
          name: VOLUME.imperialPints,
          leafNodes: [
            Node(
              coefficientProduct: 1 / 20,
              name: VOLUME.imperialFluidOunces,
              leafNodes: [
                Node(coefficientProduct: 5, name: VOLUME.imperialGill),
              ],
            ),
          ],
        ),
        Node(
          coefficientProduct: 0.473176473,
          name: VOLUME.usPints,
          leafNodes: [
            Node(
              coefficientProduct: 1 / 16,
              name: VOLUME.usFluidOunces,
              leafNodes: [
                Node(
                  coefficientProduct: 4,
                  name: VOLUME.usGill,
                ),
              ],
            ),
          ],
        ),
        Node(coefficientProduct: 1e-3, name: VOLUME.milliliters, leafNodes: [
          Node(
            coefficientProduct: 14.8,
            name: VOLUME.tablespoonsUs,
          ),
          Node(
            coefficientProduct: 20.0,
            name: VOLUME.australianTablespoons,
          ),
          Node(
            coefficientProduct: 240.0,
            name: VOLUME.cups,
          ),
        ]),
      ]),
      Node(coefficientProduct: 1e-6, name: VOLUME.cubicCentimeters, leafNodes: [
        Node(coefficientProduct: 16.387064, name: VOLUME.cubicInches, leafNodes: [
          Node(
            coefficientProduct: 1728.0,
            name: VOLUME.cubicFeet,
          ),
        ]),
      ]),
      Node(
        coefficientProduct: 1e-9,
        name: VOLUME.cubicMillimeters,
      ),
    ],
  );
}