@@ -21,7 +21,7 @@ const size = Size(500, 900);
2121
2222class 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}
0 commit comments