diff --git a/lib/providers/timer_provider.dart b/lib/providers/timer_provider.dart index f355d7d..298316a 100644 --- a/lib/providers/timer_provider.dart +++ b/lib/providers/timer_provider.dart @@ -5,13 +5,18 @@ import 'package:flutter/material.dart'; class TimerProvider extends ChangeNotifier { Timer? _timer; bool started = false; - int get elapsedSeconds => _timer != null ? _timer!.tick : 0; + Duration _duration = const Duration(); + int get elapsedSeconds => _duration.inSeconds; + int get elapsedMilliseconds => _duration.inMilliseconds; + final Duration _tickRate = const Duration(milliseconds: 20); void startTimer(Duration duration) { + _duration = Duration.zero; started = true; - _timer = Timer.periodic(const Duration(seconds: 1), ((timer) { - if (timer.tick >= duration.inSeconds) { - timer.cancel(); + _timer = Timer.periodic(_tickRate, ((timer) { + _duration += _tickRate; + if (elapsedSeconds >= duration.inSeconds) { + _timer?.cancel(); started = false; } notifyListeners(); @@ -22,13 +27,12 @@ class TimerProvider extends ChangeNotifier { started = false; _timer?.cancel(); _timer = null; + _duration = Duration.zero; } @override void dispose() { - started = false; - _timer?.cancel(); - _timer = null; + stopTimer(); super.dispose(); } } diff --git a/lib/providers/workout_provider.dart b/lib/providers/workout_provider.dart index 0cf3804..15ff39a 100644 --- a/lib/providers/workout_provider.dart +++ b/lib/providers/workout_provider.dart @@ -54,10 +54,9 @@ class WorkoutProvider extends ChangeNotifier { Color get currentPhaseColor => _workoutPhaseSettings[currentPhase]!['color']; AssetSource get currentPhaseSource => _workoutPhaseSettings[currentPhase]!['source']; - /* bool get isWorkoutComplete => - _workoutPhaseIndex == _workoutPhases.length - 1 && isPhaseComplete; */ void nextPhase() { + print('called next phase'); _onCompleteSubscription.cancel(); _audioPlayer.stop(); if (_workoutPhaseIndex < _workoutPhases.length - 1) { diff --git a/lib/widgets/workout_timer_widget.dart b/lib/widgets/workout_timer_widget.dart index c47bbf5..e21719d 100644 --- a/lib/widgets/workout_timer_widget.dart +++ b/lib/widgets/workout_timer_widget.dart @@ -74,10 +74,12 @@ class WorkoutTimerWidget extends StatelessWidget { width: 100, child: CircularProgressIndicator( color: workoutProvider.currentPhaseColor, - value: (workoutProvider.currentPhaseDuration.inSeconds - .toDouble() - - timerProvider.elapsedSeconds) / - workoutProvider.currentPhaseDuration.inSeconds)), + value: + (workoutProvider.currentPhaseDuration.inMilliseconds - + timerProvider.elapsedMilliseconds) + .toDouble() / + workoutProvider.currentPhaseDuration.inMilliseconds + .toDouble())), TimerWidget(duration: workoutProvider.currentPhaseDuration), ], ),