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;

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:provider/provider.dart';
import 'package:sendtrain/classes/activity_action.dart';
import 'package:sendtrain/classes/media.dart';
@ -53,7 +52,7 @@ class _ActivityViewState extends State<ActivityView> {
child: Text(
textAlign: TextAlign.left,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
'Actions:')),
'Actions')),
Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Card(
@ -65,54 +64,55 @@ class _ActivityViewState extends State<ActivityView> {
),
color: Theme.of(context).colorScheme.onPrimary,
child: Row(children: [
// LinearProgressIndicator(
// value: 0.5,
// minHeight: 100,
// color: Theme.of(context).colorScheme.error,
// semanticsLabel: 'Linear progress indicator',
// ),
Ink(
width: 70,
color: Theme.of(context).colorScheme.primaryContainer,
Ink(
width: 70,
color: Theme.of(context).colorScheme.primaryContainer,
child: Consumer<ActivityTimerModel>(
builder: (context, atm, child) {
return IconButton(
alignment: AlignmentDirectional.center,
iconSize: 30,
icon: atm.isActive
? const Icon(Icons.pause_rounded)
: const Icon(Icons.play_arrow_rounded),
onPressed: () =>
{atm.isActive ? atm.pause() : atm.start()});
},
)),
Expanded(
flex: 1,
child: Stack(alignment: Alignment.center, children: [
Container(
alignment: Alignment.center,
child: Consumer<ActivityTimerModel>(
builder: (context, atm, child) {
return IconButton(
alignment: AlignmentDirectional.center,
iconSize: 30,
icon: atm.isActive
? const Icon(Icons.pause_rounded)
: const Icon(Icons.play_arrow_rounded),
onPressed: () =>
{atm.isActive ? atm.pause : atm.start()});
return Text(
style: const TextStyle(fontSize: 20),
textAlign: TextAlign.center,
'${atm.actionCount} ${atm.currentAction['type']}');
},
)),
Expanded(
flex: 1,
child: Stack(alignment: Alignment.center, children: [
Container(
alignment: Alignment.center,
child: Consumer<ActivityTimerModel>(
),
),
Container(
alignment: Alignment.centerRight,
padding: EdgeInsets.only(right: 10),
child: Consumer<ActivityTimerModel>(
builder: (context, atm, child) {
return Text(
style: const TextStyle(fontSize: 20),
textAlign: TextAlign.center,
'${atm.actionCount} ${atm.currentAction['type']}');
},
),
),
Container(
alignment: Alignment.centerRight,
padding: EdgeInsets.only(right: 10),
child: Consumer<ActivityTimerModel>(
builder: (context, atm, child) {
return Text(
style: const TextStyle(fontSize: 15),
textAlign: TextAlign.right,
'${atm.currentAction['actionID'] + 1} | ${atm.totalActions()}');
// 'Set: ${atm.currentSet + 1}/${atm.totalSets}\nRep: ${atm.currentRep + 1}/${atm.totalReps}');
})),
])),
]))),
return Text(
style: const TextStyle(fontSize: 15),
textAlign: TextAlign.right,
'${atm.currentAction['actionID'] + 1} of ${atm.totalActions()}');
})),
])),
]))),
Padding(
padding: EdgeInsets.only(left: 14, right: 14),
child: Consumer<ActivityTimerModel>(builder: (context, atm, child) {
return LinearProgressIndicator(
value: atm.progress,
semanticsLabel: 'Activity Progress',
);
})),
ActivityActionView(action: activity.actions[0]),
]);
}