From 4e5eeec93737e15e7d31d3c6f53b1787ace2356f Mon Sep 17 00:00:00 2001 From: Joshua Burman Date: Sat, 7 Dec 2024 16:25:04 -0500 Subject: [PATCH] progress indicator --- lib/models/activity_timer_model.dart | 14 ++++- lib/widgets/activity_view.dart | 92 ++++++++++++++-------------- 2 files changed, 59 insertions(+), 47 deletions(-) diff --git a/lib/models/activity_timer_model.dart b/lib/models/activity_timer_model.dart index 2126a4d..7fa82fd 100644 --- a/lib/models/activity_timer_model.dart +++ b/lib/models/activity_timer_model.dart @@ -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; diff --git a/lib/widgets/activity_view.dart b/lib/widgets/activity_view.dart index 8ad6664..40680ca 100644 --- a/lib/widgets/activity_view.dart +++ b/lib/widgets/activity_view.dart @@ -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 { 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 { ), 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( + 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( 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( + ), + ), + Container( + alignment: Alignment.centerRight, + padding: EdgeInsets.only(right: 10), + child: Consumer( 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( - 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(builder: (context, atm, child) { + return LinearProgressIndicator( + value: atm.progress, + semanticsLabel: 'Activity Progress', + ); + })), ActivityActionView(action: activity.actions[0]), ]); }