@@ -9,27 +9,11 @@ void main() {
9
9
class MyApp extends StatelessWidget {
10
10
const MyApp ({super .key});
11
11
12
- // This widget is the root of your application.
13
12
@override
14
13
Widget build (BuildContext context) {
15
14
return MaterialApp (
16
15
title: 'Flutter Demo' ,
17
16
theme: ThemeData (
18
- // This is the theme of your application.
19
- //
20
- // TRY THIS: Try running your application with "flutter run". You'll see
21
- // the application has a blue toolbar. Then, without quitting the app,
22
- // try changing the seedColor in the colorScheme below to Colors.green
23
- // and then invoke "hot reload" (save your changes or press the "hot
24
- // reload" button in a Flutter-supported IDE, or press "r" if you used
25
- // the command line to start the app).
26
- //
27
- // Notice that the counter didn't reset back to zero; the application
28
- // state is not lost during the reload. To reset the state, use hot
29
- // restart instead.
30
- //
31
- // This works for code too, not just values: Most code changes can be
32
- // tested with just a hot reload.
33
17
colorScheme: ColorScheme .fromSeed (seedColor: Colors .deepPurple),
34
18
useMaterial3: true ,
35
19
),
@@ -41,15 +25,6 @@ class MyApp extends StatelessWidget {
41
25
class MyHomePage extends StatefulWidget {
42
26
const MyHomePage ({super .key, required this .title});
43
27
44
- // This widget is the home page of your application. It is stateful, meaning
45
- // that it has a State object (defined below) that contains fields that affect
46
- // how it looks.
47
-
48
- // This class is the configuration for the state. It holds the values (in this
49
- // case the title) provided by the parent (in this case the App widget) and
50
- // used by the build method of the State. Fields in a Widget subclass are
51
- // always marked "final".
52
-
53
28
final String title;
54
29
55
30
@override
@@ -61,50 +36,19 @@ class _MyHomePageState extends State<MyHomePage> {
61
36
62
37
void _incrementCounter () {
63
38
setState (() {
64
- // This call to setState tells the Flutter framework that something has
65
- // changed in this State, which causes it to rerun the build method below
66
- // so that the display can reflect the updated values. If we changed
67
- // _counter without calling setState(), then the build method would not be
68
- // called again, and so nothing would appear to happen.
69
39
_counter++ ;
70
40
});
71
41
}
72
42
73
43
@override
74
44
Widget build (BuildContext context) {
75
- // This method is rerun every time setState is called, for instance as done
76
- // by the _incrementCounter method above.
77
- //
78
- // The Flutter framework has been optimized to make rerunning build methods
79
- // fast, so that you can just rebuild anything that needs updating rather
80
- // than having to individually change instances of widgets.
81
45
return Scaffold (
82
46
appBar: AppBar (
83
- // TRY THIS: Try changing the color here to a specific color (to
84
- // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
85
- // change color while the other colors stay the same.
86
47
backgroundColor: Theme .of (context).colorScheme.inversePrimary,
87
- // Here we take the value from the MyHomePage object that was created by
88
- // the App.build method, and use it to set our appbar title.
89
48
title: Text (widget.title),
90
49
),
91
50
body: Center (
92
- // Center is a layout widget. It takes a single child and positions it
93
- // in the middle of the parent.
94
51
child: Column (
95
- // Column is also a layout widget. It takes a list of children and
96
- // arranges them vertically. By default, it sizes itself to fit its
97
- // children horizontally, and tries to be as tall as its parent.
98
- //
99
- // Column has various properties to control how it sizes itself and
100
- // how it positions its children. Here we use mainAxisAlignment to
101
- // center the children vertically; the main axis here is the vertical
102
- // axis because Columns are vertical (the cross axis would be
103
- // horizontal).
104
- //
105
- // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
106
- // action in the IDE, or press "p" in the console), to see the
107
- // wireframe for each widget.
108
52
mainAxisAlignment: MainAxisAlignment .center,
109
53
children: < Widget > [
110
54
const Text (
@@ -121,7 +65,7 @@ class _MyHomePageState extends State<MyHomePage> {
121
65
onPressed: _incrementCounter,
122
66
tooltip: 'Increment' ,
123
67
child: const Icon (Icons .add),
124
- ), // This trailing comma makes auto-formatting nicer for build methods.
68
+ ),
125
69
);
126
70
}
127
71
}
0 commit comments