I tried the same with the inbuilt Timer.Periodic(), but pausing and resuming was so erratic; I had a time limit of 10 seconds, but pausing and resuming multiple times causes the total recording time to go over that limit.
I stumbled across this library from an SO answer.
When I replaced Timer.Periodic with PausableTimer, I see that it is fired only once.
Here is the sample code:
int _start= 10;
void startTimer() {
_timer = PausableTimer(
Duration(seconds: 1),
() {
if (_start <= 0) {
recordVideo();
setState(() {
_isRecording = true;
});
} else {
setState(() {
_start = _start - 1;
});
}
},
)..start();
}
This method will be called when the recording button is pressed.
recordVideo() is what I call to either start recording (along with startTime()) or end recording.
I know you're busy and haven't touched Dart in years, but can you help me understand what is that I'm doing wrong here and why is it being called only once?