A library to help Dart developers to convert unities and a few other things.
English | Português
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
|
|
|
| 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
}
main() {
final hex = RGBColor(red: 255, green: 255, blue: 255).toHex;
print(hex);
}
| 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
}
| 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
}
|
|
|
| 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
}
|
|
|
|
| Hertz (Hz) |
Kilohertz (kHz) |
Megahertz (mHz) |
Gigahertz (gHz) |
main() {
final frequency = convertEnergy(
Frequency.megahertz, // from
Frequency.hertz, // to
1, // value
);
print(frequency); // 1000000
}
|
|
| 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
}
|
|
|
|
| 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
}
|
|
|
|
| Tonne |
Gram |
Kilogram |
Milligram |
| Microgram |
Stone |
Pound |
Ounce |
main() {
final mass = convertMass(
Mass.kilogram, // from
Mass.gram, // to
1, // value
);
print(mass); // 1000
}
|
|
|
| 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
}
|
|
|
|
| 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
}
|
|
|
|
|
| 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
}
|
|
|
| Celcius |
Fahrenheit |
Kelvin |
main() {
final temperature = convertTemperature(
Temperature.celcius, // from
Temperature.fahrenheit, // to
0, // value
);
print(temperature); // 32
}
|
|
|
|
|
| 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
}
|
|
|
| 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
}
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:
main() {
final mass = convertMass(Mass.kilogram, Mass.gram, 10);
print(mass);
}
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.