-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincrement-with-button.dart
More file actions
79 lines (70 loc) · 1.66 KB
/
increment-with-button.dart
File metadata and controls
79 lines (70 loc) · 1.66 KB
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
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int number1 = 0;
int number2 = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Button Test'),
),
body: Column(
children: [
pressMe1(),
pressMe2(),
displayNumber(),
],
),
),
);
}
void increment1() {
setState(() {
number1++;
});
}
void increment2() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
number2++;
});
}
Widget displayNumber() {
return Container(
margin: EdgeInsets.all(20),
child: Text("$number1 $number2"),
);
}
Widget pressMe1() {
return Container(
margin: EdgeInsets.all(20),
child: FlatButton(
child: Text('Increase Number A'),
color: Colors.blue,
textColor: Colors.white,
onPressed: increment1,
),
);
}
Widget pressMe2() {
return Container(
margin: EdgeInsets.all(20),
child: FlatButton(
child: Text('Increase Number B'),
onPressed: increment2,
),
);
}
}