Maincalc update flutter
parent
e7e615ac89
commit
f84c4cb8cc
|
@ -1,28 +0,0 @@
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
// Benutzer eingeben
|
|
||||||
print('Bitte gib deine Daten ein:');
|
|
||||||
stdout.write('Gewicht (in kg): ');
|
|
||||||
double gewicht = double.parse(stdin.readLineSync()!);
|
|
||||||
stdout.write('Strecke (in km): ');
|
|
||||||
double strecke = double.parse(stdin.readLineSync()!);
|
|
||||||
stdout.write('Zeit (in Minuten): ');
|
|
||||||
double zeit = double.parse(stdin.readLineSync()!);
|
|
||||||
|
|
||||||
// Berechnungen
|
|
||||||
double geschwindigkeitProKilometer = zeit / strecke;
|
|
||||||
double kalorienverbrauch = berechneKalorienverbrauch(strecke, gewicht);
|
|
||||||
|
|
||||||
// Ergebnisse anzeigen
|
|
||||||
print('\nErgebnisse:');
|
|
||||||
print('Geschwindigkeit pro Kilometer: ${geschwindigkeitProKilometer.toStringAsFixed(2)} Minuten');
|
|
||||||
print('Kalorienverbrauch: ${kalorienverbrauch.toStringAsFixed(2)} kcal');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Funktion zur Berechnung des Kalorienverbrauchs basierend auf dem MET-Wert und der gelaufenen Strecke
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
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'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue