89 lines
2.7 KiB
Dart
89 lines
2.7 KiB
Dart
|
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;
|
||
|
|
||
|
void _berechne() {
|
||
|
double gewicht = double.parse(_gewichtController.text);
|
||
|
double strecke = double.parse(_streckeController.text);
|
||
|
double zeit = double.parse(_zeitController.text);
|
||
|
|
||
|
setState(() {
|
||
|
_geschwindigkeitProKilometer = zeit / strecke;
|
||
|
_kalorienverbrauch = _berechneKalorienverbrauch(strecke, gewicht);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
double _berechneKalorienverbrauch(double distanzInKilometer, double gewichtDesBenutzers) {
|
||
|
double met = 7.5; // Annahme eines durchschnittlichen MET-Werts für Jogging
|
||
|
double zeitInStunden = 40 / 60; // Annahme einer Zeit von 40 Minuten, um den Kalorienverbrauch zu berechnen
|
||
|
return gewichtDesBenutzers * met * zeitInStunden;
|
||
|
}
|
||
|
|
||
|
@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'),
|
||
|
Text('Kalorienverbrauch: ${_kalorienverbrauch.toStringAsFixed(2)} kcal'),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|