2024-06-12 18:10:50 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(MyApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'Kalorienverbrauch Rechner',
|
|
|
|
theme: ThemeData(
|
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
),
|
|
|
|
home: MyHomePage(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_MyHomePageState createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
|
|
final _gewichtController = TextEditingController();
|
|
|
|
final _streckeController = TextEditingController();
|
|
|
|
final _zeitController = TextEditingController();
|
|
|
|
|
|
|
|
double _geschwindigkeitProKilometer = 0.0;
|
|
|
|
double _kalorienverbrauch = 0.0;
|
2024-06-17 19:55:29 +02:00
|
|
|
bool _isValidInput = true;
|
2024-06-12 18:10:50 +02:00
|
|
|
|
|
|
|
void _berechne() {
|
|
|
|
double gewicht = double.parse(_gewichtController.text);
|
|
|
|
double strecke = double.parse(_streckeController.text);
|
|
|
|
double zeit = double.parse(_zeitController.text);
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_geschwindigkeitProKilometer = zeit / strecke;
|
2024-06-17 19:55:29 +02:00
|
|
|
_kalorienverbrauch = _berechneKalorienverbrauch(strecke, zeit, gewicht);
|
|
|
|
_isValidInput = _kalorienverbrauch != 0;
|
2024-06-12 18:10:50 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-17 19:55:29 +02:00
|
|
|
double _berechneKalorienverbrauch(double distanzInKilometer, double zeitInMinuten, double gewichtDesBenutzers) {
|
|
|
|
double zeitInStunden = zeitInMinuten / 60;
|
|
|
|
double geschwindigkeit = distanzInKilometer / zeitInStunden;
|
|
|
|
|
|
|
|
double kcalProKg;
|
|
|
|
if (geschwindigkeit >= 7 && geschwindigkeit < 10) {
|
|
|
|
kcalProKg = 8.0;
|
|
|
|
} else if (geschwindigkeit >= 10 && geschwindigkeit < 13) {
|
|
|
|
kcalProKg = 10.0;
|
|
|
|
} else if (geschwindigkeit >= 13 && geschwindigkeit <= 15) {
|
|
|
|
kcalProKg = 12.0;
|
|
|
|
} else {
|
|
|
|
return 0.0; // Invalid speed
|
|
|
|
}
|
|
|
|
|
|
|
|
return kcalProKg * gewichtDesBenutzers * zeitInStunden;
|
2024-06-12 18:10:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('Kalorienverbrauch Rechner'),
|
|
|
|
),
|
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
TextField(
|
|
|
|
controller: _gewichtController,
|
|
|
|
decoration: InputDecoration(labelText: 'Gewicht (in kg)'),
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
),
|
|
|
|
TextField(
|
|
|
|
controller: _streckeController,
|
|
|
|
decoration: InputDecoration(labelText: 'Strecke (in km)'),
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
),
|
|
|
|
TextField(
|
|
|
|
controller: _zeitController,
|
|
|
|
decoration: InputDecoration(labelText: 'Zeit (in Minuten)'),
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
),
|
|
|
|
SizedBox(height: 20),
|
|
|
|
ElevatedButton(
|
|
|
|
onPressed: _berechne,
|
|
|
|
child: Text('Berechnen'),
|
|
|
|
),
|
|
|
|
SizedBox(height: 20),
|
|
|
|
Text('Geschwindigkeit pro Kilometer: ${_geschwindigkeitProKilometer.toStringAsFixed(2)} Minuten'),
|
2024-06-17 19:55:29 +02:00
|
|
|
_isValidInput
|
|
|
|
? Text('Kalorienverbrauch: ${_kalorienverbrauch.toStringAsFixed(2)} kcal')
|
|
|
|
: Text('Ungültige Angaben', style: TextStyle(color: Colors.red)),
|
2024-06-12 18:10:50 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-06-19 15:14:06 +02:00
|
|
|
}
|