import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(title: 'Energiebillanz Rechner'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { int _counter = 0; double _joul=0; double _energieWasser=0; double _energieEisen=0; double _aHohe=0; double _eHohe=0; double _aGeschwindigkeit=0; double _eGeschwindigkeit=0; double _gewicht=0; final myController = TextEditingController(); final controllerAnfangsgeschwindigkeit = TextEditingController(); final controllerEndgeschwindigkeit = TextEditingController(); final controllerAnfangshohe = TextEditingController(); final controllerEndhohe = TextEditingController(); final controllerGewicht = TextEditingController(); @override void dispose() { // Clean up the controller when the widget is disposed. myController.dispose(); super.dispose(); } void _incrementCounter() { setState(() { _counter++; }); } void _getErgebnis() { setState(() { _aHohe=double.parse(controllerAnfangshohe.text); _eHohe=double.parse(controllerEndhohe.text); _aGeschwindigkeit=double.parse(controllerAnfangsgeschwindigkeit.text); _eGeschwindigkeit=double.parse(controllerEndgeschwindigkeit.text); _gewicht=double.parse(controllerGewicht.text); _joul= (((_gewicht * 9.8 * _aHohe) + ((_gewicht * (_aGeschwindigkeit * _aGeschwindigkeit)) / 2)) - ((_gewicht * 9.8 * _eHohe) + ((_gewicht * (_eGeschwindigkeit * _eGeschwindigkeit)) / 2))); _energieWasser = (_joul / (4186 * 80)); _energieEisen = (_joul / (500 * 680)); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( // Here we take the value from the MyHomePage object that was created by // the App.build method, and use it to set our appbar title. title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ TextField( controller: controllerAnfangsgeschwindigkeit, // int a= myController.Integer.parseInt(), decoration: InputDecoration( border: OutlineInputBorder(), hintText: 'Anfangsgeschwindigkeit', ), ), TextField( controller: controllerEndgeschwindigkeit, decoration: InputDecoration( border: OutlineInputBorder(), hintText: 'Endgeschwindigkeit', ), ), TextField( controller: controllerAnfangshohe, decoration: InputDecoration( border: OutlineInputBorder(), hintText: 'Anfangshöhe', ), ), TextField( controller: controllerEndhohe, decoration: InputDecoration( border: OutlineInputBorder(), hintText: 'Endhöhe', ), ), TextField( controller: controllerGewicht, decoration: InputDecoration( border: OutlineInputBorder(), hintText: 'Gewicht des Objekts', ), ), TextButton( style: ButtonStyle( foregroundColor: MaterialStateProperty.all(Colors.blue), ), onPressed: _getErgebnis, child: Text('berechnen'), ), Text( 'Ergebnis in Joul $_joul', ), Text( 'Ergebnis in Liter Wasser zum Kochen zubringen= $_energieWasser', ), Text( 'Ergebnis in Kg Eisen zum Glühen zubringen= $_energieEisen', ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', child: const Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods. ); } }