@@ -73,12 +73,23 @@ class CircularCountDownTimer extends StatefulWidget {
73
73
/// Handles the timer start.
74
74
final bool autoStart;
75
75
76
+ /*
77
+ * Function to format the text.
78
+ * Allows you to format the current duration to any String.
79
+ * It also provides the default function in case you want to format specific moments
80
+ as in reverse when reaching '0' show 'GO', and for the rest of the instances follow
81
+ the default behavior.
82
+ */
83
+ final Function (Function (Duration duration) defaultFormatterFunction,
84
+ Duration duration)? timeFormatterFunction;
85
+
76
86
const CircularCountDownTimer ({
77
87
required this .width,
78
88
required this .height,
79
89
required this .duration,
80
90
required this .fillColor,
81
91
required this .ringColor,
92
+ this .timeFormatterFunction,
82
93
this .backgroundColor,
83
94
this .fillGradient,
84
95
this .ringGradient,
@@ -114,10 +125,20 @@ class CircularCountDownTimerState extends State<CircularCountDownTimer>
114
125
if (widget.isReverse &&
115
126
! widget.autoStart &&
116
127
! countDownController! .isStarted) {
117
- timeStamp = _getTime (Duration (seconds: widget.duration));
128
+ if (widget.timeFormatterFunction != null ) {
129
+ return Function .apply (widget.timeFormatterFunction! ,
130
+ [_getTime, Duration (seconds: widget.duration)]).toString ();
131
+ } else {
132
+ timeStamp = _getTime (Duration (seconds: widget.duration));
133
+ }
118
134
} else {
119
135
Duration ? duration = _controller! .duration! * _controller! .value;
120
- timeStamp = _getTime (duration);
136
+ if (widget.timeFormatterFunction != null ) {
137
+ return Function .apply (
138
+ widget.timeFormatterFunction! , [_getTime, duration]).toString ();
139
+ } else {
140
+ timeStamp = _getTime (duration);
141
+ }
121
142
}
122
143
if (widget.onChange != null ) widget.onChange !(timeStamp);
123
144
@@ -308,7 +329,10 @@ class CircularCountDownTimerState extends State<CircularCountDownTimer>
308
329
class CountDownController {
309
330
CircularCountDownTimerState ? _state;
310
331
bool ? _isReverse;
311
- bool isStarted = false , isPaused = false , isResumed = false ;
332
+ bool isStarted = false ,
333
+ isPaused = false ,
334
+ isResumed = false ,
335
+ isRestarted = false ;
312
336
int ? _initialDuration, _duration;
313
337
314
338
/// This Method Starts the Countdown Timer
@@ -324,6 +348,9 @@ class CountDownController {
324
348
from: _initialDuration == 0 ? 0 : (_initialDuration! / _duration! ));
325
349
}
326
350
isStarted = true ;
351
+ isPaused = false ;
352
+ isResumed = false ;
353
+ isRestarted = false ;
327
354
}
328
355
}
329
356
@@ -332,6 +359,7 @@ class CountDownController {
332
359
if (_state != null && _state? ._controller != null ) {
333
360
_state? ._controller? .stop (canceled: false );
334
361
isPaused = true ;
362
+ isRestarted = false ;
335
363
isResumed = false ;
336
364
}
337
365
}
@@ -345,6 +373,7 @@ class CountDownController {
345
373
_state? ._controller? .forward (from: _state! ._controller! .value);
346
374
}
347
375
isResumed = true ;
376
+ isRestarted = false ;
348
377
isPaused = false ;
349
378
}
350
379
}
@@ -362,6 +391,7 @@ class CountDownController {
362
391
_state? ._controller? .forward (from: 0 );
363
392
}
364
393
isStarted = true ;
394
+ isRestarted = true ;
365
395
isPaused = false ;
366
396
isResumed = false ;
367
397
}
@@ -372,6 +402,7 @@ class CountDownController {
372
402
if (_state != null && _state? ._controller != null ) {
373
403
_state? ._controller? .reset ();
374
404
isStarted = _state? .widget.autoStart ?? false ;
405
+ isRestarted = false ;
375
406
isPaused = false ;
376
407
isResumed = false ;
377
408
}
0 commit comments