Skip to content

Commit 00d163c

Browse files
committed
add: timer
1 parent b87d9d2 commit 00d163c

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

lib/screen/home_screen.dart

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:flutter/material.dart';
24

35
class HomeScreen extends StatefulWidget {
@@ -8,6 +10,22 @@ class HomeScreen extends StatefulWidget {
810
}
911

1012
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+
1129
@override
1230
Widget build(BuildContext context) {
1331
return Scaffold(
@@ -19,25 +37,26 @@ class _HomeScreenState extends State<HomeScreen> {
1937
child: Container(
2038
alignment: Alignment.bottomCenter,
2139
child: Text(
22-
"25:00",
40+
'$totalSeconds',
2341
style: TextStyle(
2442
color: Theme.of(context).cardColor,
25-
fontWeight: FontWeight.w600,
2643
fontSize: 89,
44+
fontWeight: FontWeight.w600,
2745
),
2846
),
2947
),
3048
),
3149
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+
),
4160
Flexible(
4261
flex: 1,
4362
child: Row(
@@ -46,12 +65,13 @@ class _HomeScreenState extends State<HomeScreen> {
4665
child: Container(
4766
decoration: BoxDecoration(
4867
color: Theme.of(context).cardColor,
68+
borderRadius: BorderRadius.circular(50),
4969
),
5070
child: Column(
5171
mainAxisAlignment: MainAxisAlignment.center,
5272
children: [
5373
Text(
54-
"Pomodors",
74+
'Pomodoros',
5575
style: TextStyle(
5676
fontSize: 20,
5777
fontWeight: FontWeight.w600,
@@ -60,7 +80,7 @@ class _HomeScreenState extends State<HomeScreen> {
6080
),
6181
),
6282
Text(
63-
"0",
83+
'0',
6484
style: TextStyle(
6585
fontSize: 58,
6686
fontWeight: FontWeight.w600,
@@ -74,7 +94,7 @@ class _HomeScreenState extends State<HomeScreen> {
7494
),
7595
],
7696
),
77-
),
97+
)
7898
],
7999
),
80100
);

0 commit comments

Comments
 (0)