upgraded dart and packages, analyze fixes, action type timer management

This commit is contained in:
Joshua Burman 2024-12-07 13:13:45 -05:00
parent 19f835d8f2
commit f781001d3b
11 changed files with 104 additions and 182 deletions

1
.gitignore vendored
View File

@ -32,6 +32,7 @@ migrate_working_dir/
.pub/ .pub/
/build/ /build/
pubspec.lock pubspec.lock
devtools_options.yaml
# Symbolication related # Symbolication related
app.*.symbols app.*.symbols

View File

@ -18,12 +18,14 @@ class ActivityAction {
List<List<Map<String, dynamic>>> items() { List<List<Map<String, dynamic>>> items() {
List<List<Map<String, dynamic>>> sets = []; List<List<Map<String, dynamic>>> sets = [];
Reps reps = activityActionSet.reps; Reps reps = activityActionSet.reps;
int totalActions = 1;
for (int i = 0; i < activityActionSet.total; i++) { for (int i = 0; i < activityActionSet.total; i++) {
List<Map<String, dynamic>> actions = []; List<Map<String, dynamic>> actions = [];
int? weight = _setWeight(i); int? weight = _setWeight(i);
actions.add({ actions.add({
'actionID': totalActions++,
'name': title, 'name': title,
'type': reps.type, 'type': reps.type,
'amount': reps.amounts[i], 'amount': reps.amounts[i],
@ -33,6 +35,7 @@ class ActivityAction {
if (activityActionSet.type == 'alternating') { if (activityActionSet.type == 'alternating') {
if (reps.rest != null) { if (reps.rest != null) {
actions.add({ actions.add({
'actionID': totalActions++,
'name': 'Rest', 'name': 'Rest',
'type': 'seconds', 'type': 'seconds',
'amount': reps.amounts[i], 'amount': reps.amounts[i],
@ -40,6 +43,7 @@ class ActivityAction {
} }
actions.add({ actions.add({
'actionID': totalActions++,
'name': title, 'name': title,
'type': reps.type, 'type': reps.type,
'amount': reps.amounts[i], 'amount': reps.amounts[i],
@ -48,6 +52,7 @@ class ActivityAction {
} }
actions.add({ actions.add({
'actionID': totalActions++,
'name': 'Rest', 'name': 'Rest',
'type': 'seconds', 'type': 'seconds',
'amount': activityActionSet.rest ~/ 1000, 'amount': activityActionSet.rest ~/ 1000,

View File

@ -1,35 +1,36 @@
import 'dart:async'; import 'dart:async';
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:sendtrain/models/activity_model.dart'; import 'package:sendtrain/models/activity_model.dart';
class ActivityTimerModel with ChangeNotifier { class ActivityTimerModel with ChangeNotifier {
int _actionCount = 0; int _actionCounter = 0;
ActivityModel? _activity; ActivityModel? _activity;
List _actions = []; List _sets = [];
int _currentActionNum = 0; int _currentActionNum = 0;
int _currentSetNum = 0; int _currentSetNum = 0;
Timer? _periodicTimer; Timer? _periodicTimer;
int get actionCount => _actionCount; int get actionCount => _actionCounter;
int get currentActionNum => _currentActionNum; int get currentActionNum => _currentActionNum;
dynamic get currentAction => currentSet[_currentActionNum];
int get currentSetNum => _currentSetNum; int get currentSetNum => _currentSetNum;
dynamic get currentSet => _sets[_currentSetNum];
ActivityModel? get activity => _activity; ActivityModel? get activity => _activity;
List get actions => _actions; List get sets => _sets;
Timer? get periodicTimer => _periodicTimer; Timer? get periodicTimer => _periodicTimer;
String get currentActionType => _actions[_currentSetNum][_currentActionNum]['type']; bool get isActive => _isActive();
void get pause => _periodicTimer!.cancel(); void get pause => _periodicTimer!.cancel();
void setup(ActivityModel activity) { void setup(ActivityModel activity) {
_activity = activity; _activity = activity;
_actions = activity.actions[0].items(); _sets = activity.actions[0].items();
_currentActionNum = 0; _currentActionNum = 0;
_currentSetNum = 0; _currentSetNum = 0;
setActionCount(); setActionCount();
} }
bool isActive() { bool _isActive() {
return (_periodicTimer != null && _periodicTimer!.isActive) ? true : false; return (_periodicTimer != null && _periodicTimer!.isActive) ? true : false;
} }
@ -43,20 +44,30 @@ class ActivityTimerModel with ChangeNotifier {
int totalActions() { int totalActions() {
int count = 0; int count = 0;
for(int i = 0; i < _actions.length; i++) { for(int i = 0; i < _sets.length; i++) {
count = count + _actions[i].length as int; count = count + _sets[i].length as int;
} }
return count; return count;
} }
void setActionCount() { void setActionCount() {
_actionCount = _actions[_currentSetNum][_currentActionNum]['amount']; _actionCounter = _sets[_currentSetNum][_currentActionNum]['amount'];
} }
void start() { void start() {
_periodicTimer = Timer.periodic(const Duration(seconds: 1), (Timer timer) { _periodicTimer = Timer.periodic(const Duration(seconds: 1), (Timer timer) {
_actionCount--; switch(currentAction['type']) {
case 'repititions':
break;
case 'seconds':
if (_actionCounter > 0) {
_actionCounter--;
} else {
nextAction(_currentActionNum + 1);
}
}
notifyListeners(); notifyListeners();
}); });
} }
@ -67,17 +78,25 @@ class ActivityTimerModel with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
void nextAction(int nextActionID) {
}
(int, int) _findAction(int actionID) {
return (1, 2);
}
// void nextAction(String type) { // void nextAction(String type) {
// setAction(_currentActionNum + 1, _getSet(), type); // setAction(_currentActionNum + 1, _getSet(), type);
// } // }
// int _actionCount = 0; // int _actionCounter = 0;
// int _currentAction = 0; // int _currentAction = 0;
// ActivityModel? _activity; // ActivityModel? _activity;
// Timer? _periodicTimer; // Timer? _periodicTimer;
// List<String> _actionMap = []; // List<String> _actionMap = [];
// int get actionCount => _actionCount; // int get actionCount => _actionCounter;
// int get currentAction => _currentAction; // int get currentAction => _currentAction;
// ActivityModel? get activity => _activity; // ActivityModel? get activity => _activity;
// Timer? get periodicTimer => _periodicTimer; // Timer? get periodicTimer => _periodicTimer;
@ -123,9 +142,9 @@ class ActivityTimerModel with ChangeNotifier {
// void getValue() { // void getValue() {
// if (_actionMap[_currentAction] == "Rest") { // if (_actionMap[_currentAction] == "Rest") {
// _actionCount = _activity!.actions[0].activityActionSet.rest ~/ 1000; // _actionCounter = _activity!.actions[0].activityActionSet.rest ~/ 1000;
// } else { // } else {
// _actionCount = _activity!.actions[0].activityActionSet.reps.amounts[0]; // _actionCounter = _activity!.actions[0].activityActionSet.reps.amounts[0];
// } // }
// } // }
@ -159,10 +178,10 @@ class ActivityTimerModel with ChangeNotifier {
// _periodicTimer?.cancel(); // _periodicTimer?.cancel();
// _periodicTimer = // _periodicTimer =
// Timer.periodic(const Duration(seconds: 1), (Timer timer) { // Timer.periodic(const Duration(seconds: 1), (Timer timer) {
// if (_actionCount <= 0) { // if (_actionCounter <= 0) {
// nextAction('automatic'); // nextAction('automatic');
// } else if (actionState() != 'Repititions') { // } else if (actionState() != 'Repititions') {
// _actionCount--; // _actionCounter--;
// } // }
// notifyListeners(); // notifyListeners();
// }); // });

View File

@ -5,10 +5,10 @@ class ActivitiesHeader extends StatefulWidget {
const ActivitiesHeader({super.key}); const ActivitiesHeader({super.key});
@override @override
_ActivitiesHeaderState createState() => _ActivitiesHeaderState(); State<ActivitiesHeader> createState() => ActivitiesHeaderState();
} }
class _ActivitiesHeaderState extends State<ActivitiesHeader> { class ActivitiesHeaderState extends State<ActivitiesHeader> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();

View File

@ -1,15 +1,11 @@
import 'dart:async';
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.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/models/activity_timer_model.dart'; import 'package:sendtrain/models/activity_timer_model.dart';
import 'package:sendtrain/widgets/action_card.dart';
class ActivityActionView extends StatefulWidget { class ActivityActionView extends StatefulWidget {
ActivityActionView({super.key, required this.action}); const ActivityActionView({super.key, required this.action});
ActivityAction action; final ActivityAction action;
@override @override
State<ActivityActionView> createState() => ActivityActionViewState(); State<ActivityActionView> createState() => ActivityActionViewState();
@ -18,7 +14,6 @@ class ActivityActionView extends StatefulWidget {
class ActivityActionViewState extends State<ActivityActionView> { class ActivityActionViewState extends State<ActivityActionView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
int actionCount = 0;
ActivityTimerModel atm = ActivityTimerModel atm =
Provider.of<ActivityTimerModel>(context, listen: true); Provider.of<ActivityTimerModel>(context, listen: true);
List<List<Map<String, dynamic>>> sets = atm.activity!.actions[0].items(); List<List<Map<String, dynamic>>> sets = atm.activity!.actions[0].items();
@ -28,11 +23,6 @@ class ActivityActionViewState extends State<ActivityActionView> {
padding: const EdgeInsets.fromLTRB(10, 0, 10, 20), padding: const EdgeInsets.fromLTRB(10, 0, 10, 20),
itemCount: widget.action.activityActionSet.total, itemCount: widget.action.activityActionSet.total,
itemBuilder: (BuildContext context, int setNum) { itemBuilder: (BuildContext context, int setNum) {
String title = widget.action.title;
Set actionSet = widget.action.activityActionSet;
Reps setReps = actionSet.reps;
int setRest = actionSet.rest ~/ 1000;
int currentAction = 0;
List<GestureDetector> content = []; List<GestureDetector> content = [];
List<Map<String, dynamic>> set = sets[setNum]; List<Map<String, dynamic>> set = sets[setNum];
@ -48,13 +38,13 @@ class ActivityActionViewState extends State<ActivityActionView> {
}, },
child: Row(children: [ child: Row(children: [
Ink( Ink(
// width: 90, width: 70,
padding: const EdgeInsets.all(15), padding: const EdgeInsets.all(15),
color: atm.isCurrentItem(setNum, actionNum) color: atm.isCurrentItem(setNum, actionNum)
? Theme.of(context).colorScheme.primaryContainer ? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.onPrimary, : Theme.of(context).colorScheme.onPrimary,
child: child:
Text(textAlign: TextAlign.right, 'Set ${setNum + 1} ')), Text(textAlign: TextAlign.center, 'Set ${setNum + 1} ')),
Expanded( Expanded(
child: Ink( child: Ink(
padding: const EdgeInsets.all(15), padding: const EdgeInsets.all(15),
@ -67,122 +57,6 @@ class ActivityActionViewState extends State<ActivityActionView> {
]))); ])));
} }
// actionCount = actionCount + 2;
// content.addAll([
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// width: 90,
// padding: const EdgeInsets.all(15),
// color: currentAction == atm.currentAction
// ? Theme.of(context).colorScheme.primaryContainer
// : Theme.of(context).colorScheme.onPrimary,
// child: Text(textAlign: TextAlign.right,'Set ${index + 1} '));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction == atm.currentAction
// ? Theme.of(context).colorScheme.surfaceBright
// : Theme.of(context).colorScheme.surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// '$title: ${setReps.amounts[index]} ${atm.setType}')))
// ])),
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction + 1, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// width: 90,
// padding: const EdgeInsets.all(15),
// color: currentAction + 1 == atm.currentAction
// ? Theme.of(context).colorScheme.primaryContainer
// : Theme.of(context).colorScheme.onPrimary,
// child: Text(textAlign: TextAlign.right,'Rest ${index + 1}'));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 1 == atm.currentAction
// ? Theme.of(context).colorScheme.surfaceBright
// : Theme.of(context).colorScheme.surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// 'Rest: $setRest seconds')))
// ])),
// ]);
// if (actionSet.type == 'alternating') {
// actionCount = actionCount + 2;
// content.addAll([
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction + 2, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 2 == atm.currentAction
// ? Theme.of(context).colorScheme.onPrimary
// : Theme.of(context).colorScheme.primaryContainer,
// child: Text('Set: ${index + 1} '));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 2 == atm.currentAction
// ? Theme.of(context).colorScheme.onSecondary
// : Theme.of(context)
// .colorScheme
// .surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// '$title: ${setReps.amounts[index]} ${atm.setType}')))
// ])),
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction + 3, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 3 == atm.currentAction
// ? Theme.of(context).colorScheme.onPrimary
// : Theme.of(context).colorScheme.primaryContainer,
// child: Text('Set: ${index + 1} '));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 3 == atm.currentAction
// ? Theme.of(context).colorScheme.onSecondary
// : Theme.of(context)
// .colorScheme
// .surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// 'Rest: $setRest seconds')))
// ])),
// ]);
// }
if (setNum == 0) { if (setNum == 0) {
return Card( return Card(
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(

View File

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:sendtrain/classes/media.dart'; import 'package:sendtrain/classes/media.dart';
import 'package:sendtrain/models/activity_model.dart'; import 'package:sendtrain/models/activity_model.dart';
import 'package:sendtrain/widgets/activity_view.dart'; import 'package:sendtrain/widgets/activity_view.dart';
import 'package:sendtrain/widgets/media_card.dart';
class ActivityCard extends StatelessWidget { class ActivityCard extends StatelessWidget {
const ActivityCard({super.key, required this.activity}); const ActivityCard({super.key, required this.activity});

View File

@ -8,8 +8,8 @@ import 'package:sendtrain/widgets/activity_action_view.dart';
import 'package:sendtrain/widgets/media_card.dart'; import 'package:sendtrain/widgets/media_card.dart';
class ActivityView extends StatefulWidget { class ActivityView extends StatefulWidget {
ActivityView({super.key, required this.activity}); const ActivityView({super.key, required this.activity});
ActivityModel activity; final ActivityModel activity;
@override @override
State<ActivityView> createState() => _ActivityViewState(); State<ActivityView> createState() => _ActivityViewState();
@ -56,44 +56,62 @@ class _ActivityViewState extends State<ActivityView> {
Padding( Padding(
padding: const EdgeInsets.only(left: 10, right: 10), padding: const EdgeInsets.only(left: 10, right: 10),
child: Card( child: Card(
clipBehavior: Clip.antiAlias,
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)), borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)),
), ),
color: Theme.of(context).colorScheme.onPrimary, color: Theme.of(context).colorScheme.onPrimary,
child: Row(children: [ child: Padding(
padding: const EdgeInsets.only(left: 0, right: 0),
child: Row(children: [
// LinearProgressIndicator( // LinearProgressIndicator(
// value: 0.5, // value: 0.5,
// minHeight: 100, // minHeight: 100,
// color: Theme.of(context).colorScheme.error, // color: Theme.of(context).colorScheme.error,
// semanticsLabel: 'Linear progress indicator', // semanticsLabel: 'Linear progress indicator',
// ), // ),
Expanded( // Expanded(
flex: 1, // flex: 1,
child: Flex(direction: Axis.horizontal, children: [ // child: Flex(direction: Axis.horizontal, children: [
Consumer<ActivityTimerModel>(builder: (context, atm, child) { // Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return IconButton(
// iconSize: 30,
// icon: atm.isActive()
// ? const Icon(Icons.pause_rounded)
// : const Icon(Icons.play_arrow_rounded),
// onPressed: () =>
// {atm.isActive() ? atm.pause : atm.start()});
// }),
// // IconButton(
// // // iconSize: 36,
// // icon: const Icon(Icons.skip_next_rounded),
// // onPressed: () {
// // atm.nextAction('manual');
// // })
// ])),
Ink(
width: 70,
color: Theme.of(context).colorScheme.primaryContainer,
child: Consumer<ActivityTimerModel>(
builder: (context, atm, child) {
return IconButton( return IconButton(
// iconSize: 30, alignment: AlignmentDirectional.center,
icon: atm.isActive() iconSize: 30,
? const Icon(Icons.pause_rounded) icon: atm.isActive
: const Icon(Icons.play_arrow_rounded), ? const Icon(Icons.pause_rounded)
onPressed: () => : const Icon(Icons.play_arrow_rounded),
{atm.isActive() ? atm.pause : atm.start()}); onPressed: () =>
}), {atm.isActive ? atm.pause : atm.start()});
// IconButton( },
// // iconSize: 36, )),
// icon: const Icon(Icons.skip_next_rounded),
// onPressed: () {
// atm.nextAction('manual');
// })
])),
Expanded( Expanded(
flex: 1, flex: 2,
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: 20),
textAlign: TextAlign.center, textAlign: TextAlign.right,
'${atm.actionCount} ${atm.currentActionType}'); '${atm.actionCount} ${atm.currentAction['type']}');
}, },
)), )),
Expanded( Expanded(
@ -103,12 +121,12 @@ class _ActivityViewState extends State<ActivityView> {
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.right, textAlign: TextAlign.right,
'${atm.currentActionNum + 1} / ${atm.totalActions()}'); '${atm.currentAction['actionID']} | ${atm.totalActions()}');
// 'Set: ${atm.currentSet + 1}/${atm.totalSets}\nRep: ${atm.currentRep + 1}/${atm.totalReps}'); // 'Set: ${atm.currentSet + 1}/${atm.totalSets}\nRep: ${atm.currentRep + 1}/${atm.totalReps}');
}))), }))),
]))), ])))),
ActivityActionView(action: activity.actions[0]), ActivityActionView(action: activity.actions[0]),
// Container( // Container(
// height: MediaQuery.sizeOf(context).height * .07, // height: MediaQuery.sizeOf(context).height * .07,

View File

@ -5,6 +5,8 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import flutter_inappwebview_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
} }

View File

@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 0.2.1 version: 0.2.1
environment: environment:
sdk: '>=2.19.2 <3.0.0' sdk: '>=3.0.0 <4.0.0'
# Dependencies specify other packages that your package needs in order to work. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions
@ -36,8 +36,8 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
scaler: ^1.1.2+1 scaler: ^1.1.2+1
intl: ^0.18.0 intl: ^0.20.1
youtube_player_flutter: ^8.1.2 youtube_player_flutter: ^9.1.1
json_annotation: ^4.9.0 json_annotation: ^4.9.0
provider: ^6.1.2 provider: ^6.1.2
@ -53,7 +53,7 @@ dev_dependencies:
# activated in the `analysis_options.yaml` file located at the root of your # activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint # package. See that file for information about deactivating specific lint
# rules and activating additional ones. # rules and activating additional ones.
flutter_lints: ^2.0.0 flutter_lints: ^5.0.0
build_runner: ^2.4.13 build_runner: ^2.4.13
json_serializable: ^6.9.0 json_serializable: ^6.9.0

View File

@ -6,6 +6,9 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterInappwebviewWindowsPluginCApi"));
} }

View File

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_inappwebview_windows
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST