1
+ import 'dart:async' ;
2
+
1
3
import 'package:flutter/material.dart' ;
2
4
3
5
class HomeScreen extends StatefulWidget {
@@ -8,6 +10,22 @@ class HomeScreen extends StatefulWidget {
8
10
}
9
11
10
12
class _HomeScreenState extends State <HomeScreen > {
13
+ int totalSeconds = 1500 ;
14
+ late Timer timer;
15
+
16
+ void onTick (Timer timer) {
17
+ setState (() {
18
+ totalSeconds = totalSeconds - 1 ;
19
+ });
20
+ }
21
+
22
+ void onStartPressed () {
23
+ timer = Timer .periodic (
24
+ const Duration (seconds: 1 ),
25
+ onTick,
26
+ );
27
+ }
28
+
11
29
@override
12
30
Widget build (BuildContext context) {
13
31
return Scaffold (
@@ -19,25 +37,26 @@ class _HomeScreenState extends State<HomeScreen> {
19
37
child: Container (
20
38
alignment: Alignment .bottomCenter,
21
39
child: Text (
22
- "25:00" ,
40
+ '$ totalSeconds ' ,
23
41
style: TextStyle (
24
42
color: Theme .of (context).cardColor,
25
- fontWeight: FontWeight .w600,
26
43
fontSize: 89 ,
44
+ fontWeight: FontWeight .w600,
27
45
),
28
46
),
29
47
),
30
48
),
31
49
Flexible (
32
- flex: 3 ,
33
- child: Center (
34
- child: IconButton (
35
- iconSize: 120 ,
36
- color: Theme .of (context).cardColor,
37
- onPressed: () {},
38
- icon: const Icon (Icons .play_circle_outline),
39
- ),
40
- )),
50
+ flex: 3 ,
51
+ child: Center (
52
+ child: IconButton (
53
+ iconSize: 120 ,
54
+ color: Theme .of (context).cardColor,
55
+ onPressed: onStartPressed,
56
+ icon: const Icon (Icons .play_circle_outline),
57
+ ),
58
+ ),
59
+ ),
41
60
Flexible (
42
61
flex: 1 ,
43
62
child: Row (
@@ -46,12 +65,13 @@ class _HomeScreenState extends State<HomeScreen> {
46
65
child: Container (
47
66
decoration: BoxDecoration (
48
67
color: Theme .of (context).cardColor,
68
+ borderRadius: BorderRadius .circular (50 ),
49
69
),
50
70
child: Column (
51
71
mainAxisAlignment: MainAxisAlignment .center,
52
72
children: [
53
73
Text (
54
- "Pomodors" ,
74
+ 'Pomodoros' ,
55
75
style: TextStyle (
56
76
fontSize: 20 ,
57
77
fontWeight: FontWeight .w600,
@@ -60,7 +80,7 @@ class _HomeScreenState extends State<HomeScreen> {
60
80
),
61
81
),
62
82
Text (
63
- "0" ,
83
+ '0' ,
64
84
style: TextStyle (
65
85
fontSize: 58 ,
66
86
fontWeight: FontWeight .w600,
@@ -74,7 +94,7 @@ class _HomeScreenState extends State<HomeScreen> {
74
94
),
75
95
],
76
96
),
77
- ),
97
+ )
78
98
],
79
99
),
80
100
);
0 commit comments