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

View File

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