handle stop
parent
4144bbaf69
commit
c1cf3cce30
|
@ -18,5 +18,8 @@ class TimerProvider extends ChangeNotifier {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopTimer() => _timer?.cancel();
|
void stopTimer() {
|
||||||
|
started = false;
|
||||||
|
_timer?.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ class WorkoutProvider extends ChangeNotifier {
|
||||||
final AudioPlayer _audioPlayer = AudioPlayer();
|
final AudioPlayer _audioPlayer = AudioPlayer();
|
||||||
final Source _finishedSoundSource = AssetSource('finish.mp3');
|
final Source _finishedSoundSource = AssetSource('finish.mp3');
|
||||||
final Source _beepSoundSource = AssetSource('beep.mp3');
|
final Source _beepSoundSource = AssetSource('beep.mp3');
|
||||||
|
bool isWorkoutStarted = false;
|
||||||
|
|
||||||
WorkoutProvider(this.timerProvider);
|
WorkoutProvider(this.timerProvider);
|
||||||
|
|
||||||
|
@ -57,10 +58,19 @@ class WorkoutProvider extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
void startWorkout() {
|
void startWorkout() {
|
||||||
|
isWorkoutStarted = true;
|
||||||
_audioPlayer.play(_beepSoundSource);
|
_audioPlayer.play(_beepSoundSource);
|
||||||
_audioPlayer.onPlayerComplete.listen((event) {
|
_audioPlayer.onPlayerComplete.listen((event) {
|
||||||
_audioPlayer.play(_phaseSongSources[currentPhase]!);
|
_audioPlayer.play(_phaseSongSources[currentPhase]!);
|
||||||
timerProvider.startTimer(currentPhaseDuration);
|
timerProvider.startTimer(currentPhaseDuration);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stopWorkout() {
|
||||||
|
isWorkoutStarted = false;
|
||||||
|
_workoutPhaseIndex = 0;
|
||||||
|
_audioPlayer.stop();
|
||||||
|
timerProvider.stopTimer();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@ class WorkoutTimerWidget extends StatelessWidget {
|
||||||
Text(workoutProvider.currentPhase),
|
Text(workoutProvider.currentPhase),
|
||||||
TimerWidget(duration: workoutProvider.currentPhaseDuration),
|
TimerWidget(duration: workoutProvider.currentPhaseDuration),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () => workoutProvider.startWorkout(),
|
onPressed: !workoutProvider.isWorkoutStarted
|
||||||
|
? () => workoutProvider.startWorkout()
|
||||||
|
: () => workoutProvider.stopWorkout(),
|
||||||
child: Text(timerProvider.started ? 'Stop' : 'Start'))
|
child: Text(timerProvider.started ? 'Stop' : 'Start'))
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue