progress indicator

This commit is contained in:
Joshua Burman
2024-12-07 16:25:04 -05:00
parent 0c0f596fbb
commit 4e5eeec937
2 changed files with 59 additions and 47 deletions

View File

@ -10,6 +10,7 @@ class ActivityTimerModel with ChangeNotifier {
int _currentActionNum = 0;
int _currentSetNum = 0;
Timer? _periodicTimer;
double _progress = 0;
int get actionCount => _actionCounter;
int get currentActionNum => _currentActionNum;
@ -20,7 +21,7 @@ class ActivityTimerModel with ChangeNotifier {
List get sets => _sets;
Timer? get periodicTimer => _periodicTimer;
bool get isActive => _isActive();
void get pause => _periodicTimer!.cancel();
double get progress => _progress;
void setup(ActivityModel activity) {
_activity = activity;
@ -51,6 +52,11 @@ class ActivityTimerModel with ChangeNotifier {
_actionCounter = currentAction['amount'];
}
void pause() {
_periodicTimer!.cancel();
notifyListeners();
}
void start() {
_periodicTimer = Timer.periodic(const Duration(seconds: 1), (Timer timer) {
switch (currentAction['type']) {
@ -65,12 +71,18 @@ class ActivityTimerModel with ChangeNotifier {
nextAction(_currentActionNum + 1);
setActionCount();
}
updateProgress();
}
notifyListeners();
});
}
void updateProgress() {
_progress = (currentAction['actionID'] + (1.0 - _actionCounter / currentAction['amount'])) / totalActions();
notifyListeners();
}
void setAction(int setNum, int actionNum, String type) {
_currentActionNum = actionNum;
_currentSetNum = setNum;