unit_convert 0.1.3 unit_convert: ^0.1.3 copied to clipboard
A Dart unit converter to convert between numerous units easily.
Usage #
Conversions #
You can use the convert
function to convert between most units:
import 'package:unit_convert/unit_convert.dart';
// (from) (to)
double result = convert(celsius, fahrenheit, 100);
or using the to
method on each unit:
double result = celsius.to(fahrenheit, 100);
or shorthand using function invocation:
double result = celsius(fahrenheit, 100);
or using from
for more clarity:
double result = from(celsius).to(fahrenheit, 100);
The most commonly used units are already imported by default. If you need to convert between less commonly used units, please use the enum of the unit category:
double result = convert(LengthUnit.astronomicalUnit, LengthUnit.lightYear, 100000);
double result = TimeUnit.leapYear.to(TimeUnit.quindecinnal, 10);
double result = from(EnergyUnit.kilocalorie).to(EnergyUnit.wattHour, 1000);