Skip to content

Commit 2a06839

Browse files
authored
Fixed timer issues (#31)
* Fixed timer issues * bump app version * minor improvement
1 parent 6f39a6c commit 2a06839

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

lib/countdown_screen.dart

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const size = Size(500, 900);
2121

2222
class CountdownScreenState extends State<CountdownScreen> with WindowListener {
2323
RocketTimer? _timer;
24-
bool inProgress = false;
24+
bool inBreak = false;
2525
bool isPaused = false;
2626
late ValueNotifier<bool> forceModeEnabled = ValueNotifier(false);
2727
WindowOptions windowOptions = const WindowOptions(
@@ -37,6 +37,8 @@ class CountdownScreenState extends State<CountdownScreen> with WindowListener {
3737

3838
late int reminder;
3939
late int breakTime;
40+
Duration get workDuration => Duration(minutes: reminder);
41+
Duration get breakDuration => Duration(seconds: breakTime);
4042

4143
@override
4244
void initState() {
@@ -64,13 +66,13 @@ class CountdownScreenState extends State<CountdownScreen> with WindowListener {
6466
}
6567

6668
void initTimer() {
67-
final duration = Duration(minutes: reminder);
68-
_timer = RocketTimer(type: TimerType.countdown, duration: duration);
69+
_timer = RocketTimer(type: TimerType.countdown, duration: workDuration);
6970
_timer!.addListener(() {
7071
if (_timer!.kDuration == 0) {
7172
showNotification();
72-
_timer!.kDuration = inProgress ? duration.inSeconds : reminder;
73-
inProgress = !inProgress;
73+
_timer!.kDuration =
74+
inBreak ? workDuration.inSeconds : breakDuration.inSeconds;
75+
inBreak = !inBreak;
7476
setState(() {});
7577
}
7678
});
@@ -100,7 +102,7 @@ class CountdownScreenState extends State<CountdownScreen> with WindowListener {
100102
}
101103

102104
Future<void> handleWindowState() async {
103-
if (inProgress) {
105+
if (inBreak) {
104106
await windowManager.show();
105107
await windowManager.focus();
106108
await windowManager.setFullScreen(true);
@@ -119,8 +121,8 @@ class CountdownScreenState extends State<CountdownScreen> with WindowListener {
119121

120122
Future<void> showNotification() async {
121123
LocalNotification notification = LocalNotification(
122-
title: inProgress ? "Stay Focused 💪" : "Take a Moment 🌟",
123-
body: inProgress
124+
title: inBreak ? "Stay Focused 💪" : "Take a Moment 🌟",
125+
body: inBreak
124126
? "Keep your gaze on the screen. Remember, every 20 minutes, take a 20-second break looking at something 20 feet away."
125127
: "Step back from the screen and focus on something 20 feet away for 20 seconds. Your eyes will thank you!",
126128
);
@@ -145,19 +147,6 @@ class CountdownScreenState extends State<CountdownScreen> with WindowListener {
145147
});
146148
}
147149

148-
void resetTimer() {
149-
final duration = Duration(minutes: reminder);
150-
_timer?.stop();
151-
_timer?.kDuration = duration.inSeconds;
152-
if (isPaused) {
153-
setState(() {
154-
isPaused = false;
155-
inProgress = false;
156-
});
157-
}
158-
_timer?.start();
159-
}
160-
161150
@override
162151
Widget build(BuildContext context) {
163152
final theme = Theme.of(context);
@@ -214,7 +203,7 @@ class CountdownScreenState extends State<CountdownScreen> with WindowListener {
214203
if (_timer != null)
215204
Column(
216205
children: [
217-
RuleTimer(timer: _timer!, inProgress: inProgress),
206+
RuleTimer(timer: _timer!, inBreak: inBreak),
218207
Row(
219208
mainAxisAlignment: MainAxisAlignment.center,
220209
children: [
@@ -235,7 +224,7 @@ class CountdownScreenState extends State<CountdownScreen> with WindowListener {
235224
);
236225
}),
237226
IconButton(
238-
onPressed: _timer!.restart,
227+
onPressed: _restartTimer,
239228
icon: const Icon(Icons.restart_alt)),
240229
],
241230
)
@@ -301,4 +290,11 @@ class CountdownScreenState extends State<CountdownScreen> with WindowListener {
301290
),
302291
);
303292
}
293+
294+
void _restartTimer() {
295+
_timer!.restart();
296+
inBreak = false;
297+
_timer!.kDuration = workDuration.inSeconds;
298+
setState(() {});
299+
}
304300
}

lib/widgets/custom_slider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CustomSlider extends StatelessWidget {
6464
),
6565
child: Slider(
6666
value: value.toDouble(),
67-
min: 10,
67+
min: 1,
6868
max: 60,
6969
divisions: 50,
7070
onChanged: onChanged,

lib/widgets/rule_timer.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ class RuleTimer extends StatelessWidget {
55
const RuleTimer({
66
super.key,
77
required RocketTimer timer,
8-
required this.inProgress,
8+
required this.inBreak,
99
}) : _timer = timer;
1010

1111
final RocketTimer _timer;
12-
final bool inProgress;
12+
final bool inBreak;
1313

1414
final circleSize = 200.0;
1515

1616
@override
1717
Widget build(BuildContext context) {
1818
final theme = Theme.of(context);
19-
final stroke = inProgress ? 25.0 : 15.0;
2019

2120
return SizedBox(
2221
height: circleSize + 40,
@@ -39,7 +38,7 @@ class RuleTimer extends StatelessWidget {
3938
shape: BoxShape.circle,
4039
boxShadow: [
4140
BoxShadow(
42-
color: (inProgress
41+
color: (inBreak
4342
? theme.colorScheme.secondary
4443
: theme.colorScheme.primary)
4544
.withAlpha((0.2 * 255).round()),
@@ -57,12 +56,12 @@ class RuleTimer extends StatelessWidget {
5756
timeString,
5857
style: theme.textTheme.displayMedium?.copyWith(
5958
fontWeight: FontWeight.bold,
60-
color: inProgress
59+
color: inBreak
6160
? theme.colorScheme.secondary
6261
: theme.colorScheme.primary,
6362
),
6463
),
65-
if (inProgress)
64+
if (inBreak)
6665
Text(
6766
'Break Time',
6867
style: theme.textTheme.titleMedium?.copyWith(
@@ -83,11 +82,11 @@ class RuleTimer extends StatelessWidget {
8382
height: circleSize,
8483
width: circleSize,
8584
child: CircularProgressIndicator(
86-
color: inProgress
85+
color: inBreak
8786
? theme.colorScheme.secondary
8887
: theme.colorScheme.primary,
8988
backgroundColor: theme.colorScheme.surfaceContainerHighest,
90-
strokeWidth: stroke,
89+
strokeWidth: 15.0,
9190
value: value,
9291
strokeCap: StrokeCap.round,
9392
),

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1616
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1717
# In Windows, build-name is used as the major, minor, and patch parts
1818
# of the product and file versions while build-number is used as the build suffix.
19-
version: 2.0.0
19+
version: 2.0.1
2020

2121
environment:
2222
sdk: '>=3.1.2 <4.0.0'

0 commit comments

Comments
 (0)