From be23fb469cde5e5002db18632246e5fa72176eba Mon Sep 17 00:00:00 2001 From: Luke Knoble <35696371+Desync-o-tron@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:41:50 -0400 Subject: [PATCH] polish --- lib/DOM/training_metadata.dart | 21 +++++++++++++++++++-- lib/training/training_page.dart | 13 +++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/DOM/training_metadata.dart b/lib/DOM/training_metadata.dart index 98ba906..5377892 100644 --- a/lib/DOM/training_metadata.dart +++ b/lib/DOM/training_metadata.dart @@ -66,6 +66,23 @@ class TrainingSession { ); } + bool hasEmptySets() { + for (var setsOfAnExercise in trainingData) { + for (var set in setsOfAnExercise.sets) { + bool setIsEmpty = true; + if (set.reps != null && set.reps != 0) setIsEmpty = false; + if (set.weight != null && set.weight != 0) setIsEmpty = false; + if (set.time != null && set.time != 0) setIsEmpty = false; + if (set.distance != null && set.distance != 0) setIsEmpty = false; + if (set.speed != null && set.speed != 0) setIsEmpty = false; + if (setIsEmpty) { + return true; + } + } + } + return false; + } + factory TrainingSession.fromJson(Map json) => _$TrainingSessionFromJson(json); Map toJson() => _$TrainingSessionToJson(this); @@ -102,8 +119,8 @@ class Set { MassUnits? massUnits; DistanceUnits? distanceUnits; bool completed = false; - - //todo add units. weight, distance, speed, time etc.. + //if we ever add a new setMetric, then we should update TrainingSession.hasEmptySets + //todo add a units to these weight, distance, speed, time etc.. and update the gui to proccess..maybe convience functions here Set(this.ex) { id = DateTime.now().toIso8601String(); diff --git a/lib/training/training_page.dart b/lib/training/training_page.dart index fcadd6f..f12b03a 100644 --- a/lib/training/training_page.dart +++ b/lib/training/training_page.dart @@ -36,16 +36,25 @@ class _TrainingPageState extends State { completeLabel: 'Finish', cancelLabel: 'Cancel', onCancel: () { - //todo + //todo sesh.hasCompletedSets() }, onComplete: () { //todo check if there are still empty sets final sesh = context.read().state; + if (sesh.hasEmptySets()) { + ScaffoldMessenger.of(context).showSnackBar(const SnackBar( + content: Text( + "you still have empty sets. casual. swipe 'em to remove them."))); + return; + } + sesh.isOngoing = false; sesh.duration = DateTime.now().difference(sesh.date); sesh.dateOfLastEdit = DateTime.now(); final histCubit = context.read(); - histCubit.addTrainingSessionToHistory(sesh); + if (sesh.trainingData.isNotEmpty) { + histCubit.addTrainingSessionToHistory(sesh); + } context.read().reset(); context.go(routeNames.History.text); },