changed circular progress indicator framerate

main
Julian Gegner 2023-03-04 15:30:21 +01:00
parent dd4ddc566f
commit 3038efcd27
3 changed files with 18 additions and 13 deletions

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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),
],
),