import 'package:flutter/material.dart';
class Mainwindow extends StatefulWidget {
const Mainwindow({super.key});
@override
State<StatefulWidget> createState() {
return MainState();
}
}
class MainState extends State<Mainwindow>{
TextEditingController baseController = TextEditingController();
TextEditingController heightController = TextEditingController();
TextEditingController areaController = TextEditingController();
onPressed() {
setState(() {
startCalc();
});
}
startCalc() {
double base = double.parse(baseController.text);
double height = double.parse(heightController.text);
double area = calcArea(base, height);
areaController.text = area.toString();
}
calcArea(double base, double height) {
return base * height / 2;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Háromszög')),
body: Column(children: [
const Text('Háromszög területszámítás'),
const Text('Alap'),
TextField(controller: baseController),
const Text('Magasság'),
TextField(controller: heightController),
Row(
children: [
Expanded(child:
ElevatedButton(
onPressed: onPressed,
child: const Text('Számít')
)
),
],
),
Text(areaController.text),
]),
);
}
}