progress indicator
This commit is contained in:
parent
0c0f596fbb
commit
4e5eeec937
@ -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;
|
||||||
|
@ -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,12 +64,6 @@ class _ActivityViewState extends State<ActivityView> {
|
|||||||
),
|
),
|
||||||
color: Theme.of(context).colorScheme.onPrimary,
|
color: Theme.of(context).colorScheme.onPrimary,
|
||||||
child: Row(children: [
|
child: Row(children: [
|
||||||
// LinearProgressIndicator(
|
|
||||||
// value: 0.5,
|
|
||||||
// minHeight: 100,
|
|
||||||
// color: Theme.of(context).colorScheme.error,
|
|
||||||
// semanticsLabel: 'Linear progress indicator',
|
|
||||||
// ),
|
|
||||||
Ink(
|
Ink(
|
||||||
width: 70,
|
width: 70,
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
@ -83,7 +76,7 @@ class _ActivityViewState extends State<ActivityView> {
|
|||||||
? const Icon(Icons.pause_rounded)
|
? const Icon(Icons.pause_rounded)
|
||||||
: const Icon(Icons.play_arrow_rounded),
|
: const Icon(Icons.play_arrow_rounded),
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
{atm.isActive ? atm.pause : atm.start()});
|
{atm.isActive ? atm.pause() : atm.start()});
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
Expanded(
|
Expanded(
|
||||||
@ -108,11 +101,18 @@ class _ActivityViewState extends State<ActivityView> {
|
|||||||
return Text(
|
return Text(
|
||||||
style: const TextStyle(fontSize: 15),
|
style: const TextStyle(fontSize: 15),
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
'${atm.currentAction['actionID'] + 1} | ${atm.totalActions()}');
|
'${atm.currentAction['actionID'] + 1} of ${atm.totalActions()}');
|
||||||
// 'Set: ${atm.currentSet + 1}/${atm.totalSets}\nRep: ${atm.currentRep + 1}/${atm.totalReps}');
|
|
||||||
})),
|
})),
|
||||||
])),
|
])),
|
||||||
]))),
|
]))),
|
||||||
|
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]),
|
ActivityActionView(action: activity.actions[0]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user