forked from truepixsel007/flutter_course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main71.dart
124 lines (101 loc) · 4.29 KB
/
main71.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//update correctly with stateful widget
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.yellow),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var no1Controller = TextEditingController();
var no2Controller = TextEditingController();
var result = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Container(
color: Colors.blue.shade100,
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
keyboardType: TextInputType.number,
controller: no1Controller,
),
TextField(
keyboardType: TextInputType.number,
controller: no2Controller,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(onPressed: (){
var no1 = int.parse(no1Controller.text.toString());
var no2 = int.parse(no2Controller.text.toString());
var sum = no1+ no2;
result = "The sum of $no1 and $no2 is $sum";
setState(() {
});
}, child: Text('Add')),
ElevatedButton(onPressed: (){
var no1 = int.parse(no1Controller.text.toString());
var no2 = int.parse(no2Controller.text.toString());
var diff = no1- no2;
result = "The diffenence between $no1 and $no2 is $diff";
setState(() {
});
}, child: Text('Sub')),
ElevatedButton(onPressed: (){
var no1 = int.parse(no1Controller.text.toString());
var no2 = int.parse(no2Controller.text.toString());
var mul = no1 * no2;
result = "The product of $no1 and $no2 is ${mul.toStringAsFixed(2)}"; setState(() {
});
}, child: Text('Mul')),
ElevatedButton(onPressed: (){
var no1 = int.parse(no1Controller.text.toString());
var no2 = int.parse(no2Controller.text.toString());
var div = no1 / no2;
result = "The $no1 can be divided by $no2 is ${div.toStringAsFixed(2)}";
setState(() {
});
}, child: Text('Div')),
],
),
),
Padding(padding: EdgeInsets.all(21), child: Text('Result $result',style: TextStyle(fontSize:25),),),
],
),
),
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}