unities_helper 2.1.0 icon indicating copy to clipboard operation
unities_helper: ^2.1.0 copied to clipboard

outdated

A library to help you convert unities and a few other things

A library to help Dart developers to convert unities and a few other things.

Usage #

A simple usage example:

import 'package:unities_helper/unities_helper.dart';

main() {
  /// Convert 25°C into Fahrenheit
  final temperature = convert<Temperature>(
    Temperature.celcius, // from
    Temperature.fahrenheit, // to
    25, // value
  );
  print(temperature);
}

A more detailed example can be found on the example folder

Supported conversions #

Area #

Square Kilometre (km²)Square metre (m²)Square mile (mi²)
Square yardSquare footSquare inch (in²)
HectareAcre
main() {
  final area = convertArea(
    Area.squareMetre, // from
    Area.squareKilometre, // to
    10000000, // value
  );
  print(area); // 10
}

Color spaces #

HEXHSVHSLARGB
main() {
  final hex = RGBColor(red: 255, green: 255, blue: 255).toHex;
  print(hex);
}

Data Transfer Rate #

bitkilomegagigatera
kibibitmebibitgibibittebibit
bitkilobitmegabitgigabitterabit
kilobytemegabytegigabyteterabyte
main() {
  final rate = convertDataTransferRate(
    DataTransferRate.gigabyte, // from
    DataTransferRate.megabyte, // to
    1, // value
  );
  print(rate); // 1000
}

Digital storage #

bitkilomegagigaterapeta
bitkilobitmegabitgigabitterabitpetabit
bytekibibitmebibitgibibittebibitpebibit
kilobytemegabytegigabyteterabytepetabyte
kibibytemebibytegibibytetebibytepebibyte
main() {
  final storage = convertDigitalStorage(
    DigitalStorage.gigabyte, // from
    DigitalStorage.megabyte, // to
    1, // value
  );
  print(storage); // 1000
}

Energy #

JouleKilojouleGram calorie
KilocalorieWatt-hourKilowatt-hour
electron-volttherm (US)Foot-pound
British Termal Unit
main() {
  final energy = convertEnergy(
    Energy.kilocalorie, // from
    Energy.gramCalorie, // to
    1, // value
  );
  print(energy); // 1000
}

Frequency #

Hertz (Hz)Kilohertz (kHz)Megahertz (mHz)Gigahertz (gHz)
main() {
  final frequency = convertEnergy(
    Frequency.megahertz, // from
    Frequency.hertz, // to
    1, // value
  );
  print(frequency); // 1000000
}

Fuel Economy #

Kilometer per litreLiter per 100 kilometres
Mile per US GallonMile per Imperial Gallon
main() {
  final fuel = convertFuelEconomy(
    FuelEconomy.kilometerPerLitre, // from
    FuelEconomy.milePerUsGallon, // to
    1, // value
  );
  print(fuel); // 2,35215
}

Length #

NanometerMicrometerMillimeterCentimeter
MeterKilometerInchMile
YardFeetNautical Mile
main() {
  final length = convertLength(
    Length.centimeter, // from
    Length.meter, // to
    100, // value
  );
  print(length); // 1
}

Mass #

TonneGramKilogramMilligram
MicrogramImperial TonUS tonStone
PoundOunce
main() {
  final mass = convertMass(
    Mass.kilogram, // from
    Mass.gram, // to
    1, // value
  );
  print(mass); // 1000
}

Plane Angle° #

DegreeGradianMilliradianRadian
Minute of arcSecond of arc
main() {
  final angle = convertPlaneAngle(
    PlaneAngle.degree, // from
    PlaneAngle.minuteOfArc, // to
    1, // value
  );
  print(angle); // 60
}

Pressure #

BarPascalTorrStandart Atmosphere
Pounc-force \in²

\in² = per square-inch

main() {
  final pressure = convertPressure(
    Pressure.bar, // from
    Pressure.pascal, // to
    1, // value
  );
  print(pressure); // 100000
}

Speed #

Miles/hFoot/sMetre/sKilemetre/hKnot
main() {
  final speed = convertSpeed(
    Speed.metrePerSecond, // from
    Speed.kilometrePerHour, // to
    1, // value
  );
  print(speed); // 3.6
}

Temperature #

CelciusFahrenheitKelvin
main() {
  final temperature = convertTemperature(
    Temperature.celcius, // from
    Temperature.fahrenheit, // to
    0, // value
  );
  print(temperature); // 32
}

Time #

Nanosecondmicrosendmillisecondsecondminute
hourdayweekmonthyear
decadecenturemillenium
main() {
  final time = convertTime(
    Time.minute, // from
    Time.second, // to
    1, // value
  );
  print(temperature); // 60
}

Volume #

Liquid GallonLiquid QuartLiquid Pint
CupFluid OunceTablespoon
TeaspoonCubic MetreLitre
MillilitreGallonCubic Foot
Cubic Inch
main() {
  final volume = convertVolume(
    Volume.litre, // from
    Volume.millilitre, // to
    1, // value
  );
  print(volume); // 1000
}

Using extension methods #

Instead of using convert + unit name, you can use num.as + unit name. For example, if I want to convert mass, I can do it with two ways:

Using convert method #

main() {
  final mass = convertMass(Mass.kilogram, Mass.gram, 10);
  print(mass);
}

Using extension methods #

main() {
  final mass = 10.asMass(Mass.kilogram).toGram;
  print(mass);
}

Both will print the same results. You can use extension methods with the following conversion types:

  • ✔️ Area
  • ❌ Color
  • ✔️ Data Transfer Rate
  • ✔️ Digital Storage
  • ✔️ Energy
  • ✔️ Frequency
  • ✔️ Fuel Economy
  • ✔️ Length
  • ✔️ Mass
  • ✔️ Plane Angle
  • ✔️ Pressure
  • ✔️ Speed
  • ✔️ Temperature
  • ✔️ Time
  • ✔️ Volume

Features and bugs #

Please file feature requests and bugs at the issue tracker.

5
likes
0
pub points
55%
popularity

Publisher

unverified uploader

A library to help you convert unities and a few other things

Repository (GitHub)
View/report issues

License

Icon for licenses.unknown (LICENSE)

Dependencies

meta

More

Packages that depend on unities_helper