unities_helper 3.0.0 copy "unities_helper: ^3.0.0" to clipboard
unities_helper: ^3.0.0 copied to clipboard

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.

English | Português

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 yard Square foot Square inch (in²)
Hectare Acre
main() {
  final area = convertArea(
    Area.squareMetre, // from
    Area.squareKilometre, // to
    10000000, // value
  );
  print(area); // 10
}

Color spaces #

HEX HSV HSLA RGB
main() {
  final hex = RGBColor(red: 255, green: 255, blue: 255).toHex;
  print(hex);
}

Data Transfer Rate #

bit kilo mega giga tera
kibibit mebibit gibibit tebibit
bit kilobit megabit gigabit terabit
kilobyte megabyte gigabyte terabyte
main() {
  final rate = convertDataTransferRate(
    DataTransferRate.gigabyte, // from
    DataTransferRate.megabyte, // to
    1, // value
  );
  print(rate); // 1000
}

Digital storage #

bit kilo mega giga tera peta
bit kilobit megabit gigabit terabit petabit
byte kibibit mebibit gibibit tebibit pebibit
kilobyte megabyte gigabyte terabyte petabyte
kibibyte mebibyte gibibyte tebibyte pebibyte
main() {
  final storage = convertDigitalStorage(
    DigitalStorage.gigabyte, // from
    DigitalStorage.megabyte, // to
    1, // value
  );
  print(storage); // 1000
}

Energy #

Joule Kilojoule Gram calorie
Kilocalorie Watt-hour Kilowatt-hour
electron-volt Termal Unit Foot-pound
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 litre Liter per 100 kilometres
Mile per US Gallon Mile per Imperial Gallon
main() {
  final fuel = convertFuelEconomy(
    FuelEconomy.kilometerPerLitre, // from
    FuelEconomy.milePerUsGallon, // to
    1, // value
  );
  print(fuel); // 2,35215
}

Length #

Nanometer Micrometer Millimeter Centimeter
Meter Kilometer Inch Mile
Yard Feet Nautical Mile
main() {
  final length = convertLength(
    Length.centimeter, // from
    Length.meter, // to
    100, // value
  );
  print(length); // 1
}

Mass #

Tonne Gram Kilogram Milligram
Microgram Stone Pound Ounce
main() {
  final mass = convertMass(
    Mass.kilogram, // from
    Mass.gram, // to
    1, // value
  );
  print(mass); // 1000
}

Plane Angle° #

Degree Gradian Milliradian
Radian Minute of arc Second of arc
main() {
  final angle = convertPlaneAngle(
    PlaneAngle.degree, // from
    PlaneAngle.minuteOfArc, // to
    1, // value
  );
  print(angle); // 60
}

Pressure #

Bar Pascal Torr Standart 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/h Foot/s Metre/s Kilemetre/h Knot
main() {
  final speed = convertSpeed(
    Speed.metrePerSecond, // from
    Speed.kilometrePerHour, // to
    1, // value
  );
  print(speed); // 3.6
}

Temperature #

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

Time #

Nanosecond microsend millisecond second minute
hour day week month year
decade centure millenium
main() {
  final time = convertTime(
    Time.minute, // from
    Time.second, // to
    1, // value
  );
  print(temperature); // 60
}

Volume #

Liquid Gallon Liquid Quart Liquid Pint
Cup Fluid Ounce Tablespoon
Teaspoon Cubic Metre Litre
Millilitre Gallon Cubic 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
110
pub points
49%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

meta

More

Packages that depend on unities_helper