Flutter Unity集成插件unities_helper的使用
使用
一个简单的使用示例:
import 'package:unities_helper/unities_helper.dart';
void main() {
/// 将25°C转换为华氏温度
final temperature = convert<Temperature>(
Temperature.celcius, // from
Temperature.fahrenheit, // to
25, // 值
);
print(temperature);
}
更详细的示例可以在示例文件夹中找到。
支持的转换
面积
平方公里 (km²) |
平方米 (m²) |
平方英里 (mi²) |
平方码 |
平方英尺 |
平方英寸 (in²) |
公顷 |
英亩 |
|
void main() {
final area = convertArea(
Area.squareMetre, // from
Area.squareKilometre, // to
10000000, // 值
);
print(area); // 输出 10
}
色彩空间
void main() {
final hex = RGBColor(red: 255, green: 255, blue: 255).toHex;
print(hex);
}
数据传输速率
比特 (bit) |
千比特 (kilo) |
兆比特 (mega) |
吉比特 (giga) |
太比特 (tera) |
void main() {
final rate = convertDataTransferRate(
DataTransferRate.gigabyte, // from
DataTransferRate.megabyte, // to
1, // 值
);
print(rate); // 输出 1000
}
数字存储
比特 (bit) |
千比特 (kilo) |
兆比特 (mega) |
吉比特 (giga) |
太比特 (tera) |
拍比特 (peta) |
字节 (byte) |
千字节 (kilo) |
兆字节 (mega) |
吉字节 (giga) |
太字节 (tera) |
拍字节 (peta) |
void main() {
final storage = convertDigitalStorage(
DigitalStorage.gigabyte, // from
DigitalStorage.megabyte, // to
1, // 值
);
print(storage); // 输出 1000
}
能量
焦耳 (Joule) |
千焦 (Kilojoule) |
克卡路里 (Gram calorie) |
千卡路里 (Kilocalorie) |
瓦时 (Watt-hour) |
千瓦时 (Kilowatt-hour) |
电子伏 (electron-volt) |
热力学单位 (Thermal Unit) |
英尺磅 (Foot-pound) |
void main() {
final energy = convertEnergy(
Energy.kilocalorie, // from
Energy.gramCalorie, // to
1, // 值
);
print(energy); // 输出 1000
}
频率
赫兹 (Hz) |
千赫兹 (Kilohertz) |
兆赫兹 (Megahertz) |
吉赫兹 (Gigahertz) |
|
|
|
|
void main() {
final frequency = convertFrequency(
Frequency.megahertz, // from
Frequency.hertz, // to
1, // 值
);
print(frequency); // 输出 1000000
}
燃油经济性
千米每升 (Kilometer per litre) |
升每百千米 (Liter per 100 kilometres) |
英里每加仑 (Mile per US Gallon) |
英里每加仑 (Mile per Imperial Gallon) |
void main() {
final fuel = convertFuelEconomy(
FuelEconomy.kilometerPerLitre, // from
FuelEconomy.milePerUsGallon, // to
1, // 值
);
print(fuel); // 输出 2,35215
}
长度
纳米 (Nanometer) |
微米 (Micrometer) |
毫米 (Millimeter) |
厘米 (Centimeter) |
米 (Meter) |
千米 (Kilometer) |
英寸 (Inch) |
英里 (Mile) |
码 (Yard) |
英尺 (Feet) |
海里 (Nautical Mile) |
|
void main() {
final length = convertLength(
Length.centimeter, // from
Length.meter, // to
100, // 值
);
print(length); // 输出 1
}
质量
吨 (Tonne) |
克 (Gram) |
千克 (Kilogram) |
毫克 (Milligram) |
微克 (Microgram) |
磅 (Pound) |
盎司 (Ounce) |
|
void main() {
final mass = convertMass(
Mass.kilogram, // from
Mass.gram, // to
1, // 值
);
print(mass); // 输出 1000
}
平面角
度 (Degree) |
弧度 (Radian) |
毫弧度 (Milliradian) |
梯度 (Gradian) |
分 (Minute of arc) |
秒 (Second of arc) |
void main() {
final angle = convertPlaneAngle(
PlaneAngle.degree, // from
PlaneAngle.minuteOfArc, // to
1, // 值
);
print(angle); // 输出 60
}
压力
巴 (Bar) |
帕斯卡 (Pascal) |
托 (Torr) |
标准大气压 (Standard Atmosphere) |
磅/平方英寸 (Pounc-force \in²) |
|
|
|
void main() {
final pressure = convertPressure(
Pressure.bar, // from
Pressure.pascal, // to
1, // 值
);
print(pressure); // 输出 100000
}
速度
英里/小时 (Miles/h) |
英尺/秒 (Foot/s) |
米/秒 (Metre/s) |
千米/小时 (Kilemetre/h) |
节 (Knot) |
|
|
|
|
|
void main() {
final speed = convertSpeed(
Speed.metrePerSecond, // from
Speed.kilometrePerHour, // to
1, // 值
);
print(speed); // 输出 3.6
}
温度
摄氏度 (Celcius) |
华氏度 (Fahrenheit) |
开尔文 (Kelvin) |
|
|
|
void main() {
final temperature = convertTemperature(
Temperature.celcius, // from
Temperature.fahrenheit, // to
0, // 值
);
print(temperature); // 输出 32
}
时间
纳秒 (Nanosecond) |
微秒 (microsend) |
毫秒 (millisecond) |
秒 (second) |
分钟 (minute) |
小时 (hour) |
天 (day) |
星期 (week) |
月 (month) |
年 (year) |
十年 (decade) |
百年 (centure) |
千年 (millenium) |
|
|
void main() {
final time = convertTime(
Time.minute, // from
Time.second, // to
1, // 值
);
print(time); // 输出 60
}
容量
液体加仑 (Liquid Gallon) |
液体夸脱 (Liquid Quart) |
液体品脱 (Liquid Pint) |
杯 (Cup) |
液盎司 (Fluid Ounce) |
汤匙 (Tablespoon) |
茶匙 (Teaspoon) |
立方米 (Cubic Metre) |
升 (Litre) |
毫升 (Millilitre) |
加仑 (Gallon) |
立方英尺 (Cubic Foot) |
立方英寸 (Cubic Inch) |
|
|
void main() {
final volume = convertVolume(
Volume.litre, // from
Volume.millilitre, // to
1, // 值
);
print(volume); // 输出 1000
}
使用扩展方法
除了使用 convert + 单位名称
,你还可以使用 num.as + 单位名称
。例如,如果我想将质量进行转换,我可以使用两种方式:
使用convert方法
void main() {
final mass = convertMass(Mass.kilogram, Mass.gram, 10);
print(mass);
}
使用扩展方法
void main() {
final mass = 10.asMass(Mass.kilogram).toGram;
print(mass);
}