Temp Conv
Temp Conv
dart';
void main() {
runApp(const MyApp());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: TemperatureConverter(),
);
}
}
@override
_TemperatureConverterState createState() => _TemperatureConverterState();
}
void _convertTemperature() {
double inputTemperature = double.tryParse(_controller.text) ?? 0;
setState(() {
if (_isCelsius) {
_convertedTemperature = inputTemperature * 9 / 5 + 32; // Celsius to
Fahrenheit
} else {
_convertedTemperature = (inputTemperature - 32) * 5 / 9; //
Fahrenheit to Celsius
}
});
}
void _toggleConversion() {
setState(() {
_isCelsius = !_isCelsius;
});
_convertTemperature();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ቴምፕሬቸር መለኪያ'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
TextField(
controller: _controller,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: _isCelsius ? 'Enter Celsius' : 'Enter Fahrenheit',
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: _convertTemperature,
child: Text('Convert'),
),
SizedBox(height: 20),
Text(
'Converted Temperature:
${_convertedTemperature.toStringAsFixed(2)} ${_isCelsius ? 'Fahrenheit' :
'Celsius'}',
),
SizedBox(height: 20),
ElevatedButton(
onPressed: _toggleConversion,
child: Text('Switch to ${_isCelsius ? 'Fahrenheit to Celsius' :
'Celsius to Fahrenheit'}'),
),
],
),
),
);
}
}