convertTemperature static method
Convert temperature between Celsius and Fahrenheit
temperature - Temperature value
fromUnit - Source unit ('celsius' or 'fahrenheit')
toUnit - Target unit ('celsius' or 'fahrenheit')
Returns converted temperature
Implementation
static double convertTemperature(double temperature, String fromUnit, String toUnit) {
if (fromUnit.toLowerCase() == toUnit.toLowerCase()) return temperature;
if (fromUnit.toLowerCase() == 'celsius' && toUnit.toLowerCase() == 'fahrenheit') {
return (temperature * 9 / 5) + 32;
} else if (fromUnit.toLowerCase() == 'fahrenheit' && toUnit.toLowerCase() == 'celsius') {
return (temperature - 32) * 5 / 9;
}
throw ArgumentError('Invalid temperature units');
}