[[oktatas:telefon:flutter|< Flutter]]
====== Flutter triangle ======
* **Szerző:** Sallai András
* Copyright (c) 2023, Sallai András
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== main.dart =====
import 'package:flutter/material.dart';
import 'package:triangle/screens/mainwindow.dart';
void main() {
runApp(Triangle());
}
class Triangle extends StatelessWidget {
Triangle({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: const Mainwindow(),
theme: calcTheme,
);
}
final ThemeData calcTheme = ThemeData(
inputDecorationTheme: const InputDecorationTheme(
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blueAccent),
borderRadius: BorderRadius.all(Radius.circular(15.0)),
),
),
textTheme: const TextTheme(
bodyMedium : TextStyle(fontSize: 24.0),
titleLarge: TextStyle(fontSize: 40.0),
titleMedium: TextStyle(fontSize: 24.0),
),
);
}
===== mainwindow.dart =====
import 'package:flutter/material.dart';
class Mainwindow extends StatefulWidget {
const Mainwindow({super.key});
@override
State createState() {
return MainState();
}
}
class MainState extends State{
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),
]),
);
}
}
===== Eredmény =====
{{:oktatas:telefon:flutter:flutter_triangle.png?300|}}