-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathtimer_page.dart
164 lines (154 loc) · 5.61 KB
/
timer_page.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class TimerPage extends StatefulWidget {
final String title;
TimerPage(this.title);
@override
State<StatefulWidget> createState() {
return new _TimerPageState();
}
}
class _TimerPageState extends State<TimerPage> {
TimerUtil mTimerUtil;
TimerUtil mCountDownTimerUtil;
int mTick = 0;
String timerBtnTxt = "Start";
int mCountDownTick = 0;
String countDownBtnTxt = "Start";
@override
void initState() {
super.initState();
mTimerUtil = new TimerUtil(mInterval: 1000);
//mTimerUtil.setInterval(1000);
mTimerUtil.setOnTimerTickCallback((int tick) {
setState(() {
mTick = tick;
});
});
mCountDownTimerUtil = new TimerUtil(mInterval: 1000, mTotalTime: 6 * 1000);
// mCountDownTimerUtil.setInterval(1000);
// mCountDownTimerUtil.setTotalTime(6 * 1000);
mCountDownTimerUtil.setOnTimerTickCallback((int tick) {
double _tick = tick / 1000;
if (_tick.toInt() == 0) {
countDownBtnTxt = "Start";
mCountDownTimerUtil.setTotalTime(6 * 1000);
}
setState(() {
mCountDownTick = _tick.toInt();
});
});
}
@override
void dispose() {
super.dispose();
if (mTimerUtil != null) mTimerUtil.cancel();
if (mCountDownTimerUtil != null) mCountDownTimerUtil.cancel();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
centerTitle: true,
),
body: new Column(
children: <Widget>[
new Card(
elevation: 4.0,
margin: const EdgeInsets.all(10.0),
child: new Container(
alignment: Alignment.center,
child: new Column(
children: <Widget>[
new Container(
color: Colors.grey[50],
height: 100.0,
child: new Row(
children: <Widget>[
new Container(
width: 100.0,
height: 100.0,
color: Colors.grey[100],
alignment: Alignment.center,
child: new Text("Timer"),
),
new Expanded(
child: new Container(
alignment: Alignment.center,
child: new Text('$mTick'),
),
flex: 1,
),
new InkWell(
child: new Container(
width: 100.0,
height: 100.0,
color: Colors.grey[100],
alignment: Alignment.center,
child: new Text("$timerBtnTxt"),
),
onTap: () {
if (mTimerUtil.isActive()) {
mTick = 0;
mTimerUtil.cancel();
timerBtnTxt = "Start";
} else {
mTimerUtil.startTimer();
timerBtnTxt = "Stop";
}
setState(() {});
})
],
),
),
new Container(
margin: const EdgeInsets.only(top: 10.0),
color: Colors.grey[50],
height: 100.0,
child: new Row(
children: <Widget>[
new Container(
width: 100.0,
height: 100.0,
color: Colors.grey[100],
alignment: Alignment.center,
child: new Text("CountDown"),
),
new Expanded(
child: new Container(
alignment: Alignment.center,
child: new Text('$mCountDownTick'),
),
flex: 1,
),
new InkWell(
child: new Container(
width: 100.0,
height: 100.0,
color: Colors.grey[100],
alignment: Alignment.center,
child: new Text("$countDownBtnTxt"),
),
onTap: () {
if (mCountDownTimerUtil.isActive()) {
mCountDownTimerUtil.cancel();
countDownBtnTxt = "Start";
} else {
mCountDownTimerUtil.startCountDown();
countDownBtnTxt = "Stop";
}
setState(() {});
})
],
),
),
],
),
))
],
),
);
}
}