WT 1.1.25 Training Plan Exercise Alternatives

This commit is contained in:
bossanyit
2021-12-18 18:03:52 +01:00
parent 54a61fa585
commit 05cace39bf
15 changed files with 297 additions and 734 deletions
-362
View File
@@ -1,362 +0,0 @@
import 'dart:collection';
import 'package:aitrainer_app/bloc/exercise_log/exercise_log_bloc.dart';
import 'package:aitrainer_app/widgets/app_bar.dart';
import 'package:aitrainer_app/widgets/bottom_nav.dart';
import 'package:aitrainer_app/widgets/dialog_premium.dart';
import 'package:badges/badges.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import 'package:aitrainer_app/util/app_language.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/exercise.dart';
import 'package:aitrainer_app/model/exercise_type.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/library/tree_view.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:flutter/material.dart';
import 'package:aitrainer_app/widgets/treeview_parent_widget.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
// ignore: must_be_immutable
class ExerciseLogPage extends StatelessWidget with Trans, Common {
@override
Widget build(BuildContext context) {
LinkedHashMap arguments = ModalRoute.of(context)!.settings.arguments as LinkedHashMap;
final int customerId = arguments['customerId'];
setContext(context);
return BlocProvider(
create: (context) => ExerciseLogBloc(exerciseRepository: ExerciseRepository())..add(ExerciseLogLoad()),
child: BlocConsumer<ExerciseLogBloc, ExerciseLogState>(listener: (context, state) {
if (state is ExerciseLogError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
}
}, builder: (context, state) {
final exerciseBloc = BlocProvider.of<ExerciseLogBloc>(context);
return ModalProgressHUD(
child: getExerciseLog(customerId, exerciseBloc),
inAsyncCall: state is ExerciseLogLoading,
opacity: 0.5,
color: Colors.black54,
progressIndicator: CircularProgressIndicator(),
);
}));
}
Widget getExerciseLog(int customerId, ExerciseLogBloc exerciseLogBloc) {
return Scaffold(
appBar: AppBarNav(depth: 1),
body: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
image: DecorationImage(
image: customerId == Cache().userLoggedIn!.customerId
? AssetImage('asset/image/WT_black_background.jpg')
: AssetImage('asset/image/WT_light_background.jpg'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: exerciseWidget(exerciseLogBloc, customerId),
),
bottomNavigationBar: BottomNavigator(bottomNavIndex: 1),
);
}
Widget exerciseWidget(ExerciseLogBloc exerciseLogBloc, int customerId) {
return TreeView(
startExpanded: false,
children: _getTreeChildren(exerciseLogBloc, customerId),
);
}
List<Widget> _getTreeChildren(ExerciseLogBloc exerciseLogBloc, int customerId) {
final ExerciseRepository exerciseRepository = exerciseLogBloc.exerciseRepository;
if (customerId == Cache().userLoggedIn!.customerId) {
exerciseRepository.exerciseList = exerciseRepository.getExerciseList();
} else if (Cache().getTrainee() != null && customerId == Cache().getTrainee()!.customerId) {
exerciseRepository.exerciseList = exerciseRepository.getExerciseListTrainee();
}
//print("ExerciseList ${exerciseRepository.exerciseList}");
exerciseRepository.sortByDate();
List<Widget> listWidget = [];
Card explanation = Card(
color: Colors.white60,
child: Container(
padding: EdgeInsets.only(left: 10, right: 5, top: 12, bottom: 8),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
children: [
Icon(
Icons.info,
color: Colors.orangeAccent,
),
Text(" "),
Text(
t("My Exercise Logs"),
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
],
),
Divider(
color: Colors.transparent,
),
Text(
t("In this list you will find all your executed exercises grouped by the date."),
style: TextStyle(fontSize: 12, fontWeight: FontWeight.normal),
),
],
)));
listWidget.add(explanation);
List<Exercise> listExercises = [];
String origDate = "";
exerciseRepository.exerciseLogList!.forEach((exercise) {
String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
if (origDate != exerciseDate) {
if (origDate.length == 0) {
listExercises.add(exercise);
origDate = exerciseDate;
} else {
listWidget.add(Container(
margin: const EdgeInsets.only(left: 4.0),
child: TreeViewChild(
startExpanded: false,
parent: TreeviewParentWidget(text: origDate),
children: _getChildList(listExercises, exerciseRepository, exerciseLogBloc),
)));
listExercises = [];
listExercises.add(exercise);
origDate = exerciseDate;
}
} else {
listExercises.add(exercise);
origDate = exerciseDate;
}
});
//print("ListExerices $listExercises");
if (listExercises.length > 0) {
listWidget.add(Container(
margin: const EdgeInsets.only(left: 4.0),
child: TreeViewChild(
startExpanded: true,
parent: TreeviewParentWidget(text: origDate),
children: _getChildList(listExercises, exerciseRepository, exerciseLogBloc),
)));
}
return listWidget;
}
List<Widget> _getChildList(List<Exercise> listExercises, ExerciseRepository exerciseRepository, ExerciseLogBloc exerciseLogBloc) {
List<Widget> list = [];
bool isEnglish = AppLanguage().appLocal == Locale('en');
listExercises.forEach((exercise) {
ExerciseType? exerciseType = exerciseRepository.getExerciseTypeById(exercise.exerciseTypeId!);
String exerciseName = isEnglish ? exerciseType!.name : exerciseType!.nameTranslation;
list.add(
Card(
margin: EdgeInsets.only(left: 10, top: 5),
color: Colors.white54,
child: Container(
padding: const EdgeInsets.only(left: 15, top: 0, right: 5, bottom: 0),
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Flexible(
fit: FlexFit.tight,
flex: 20,
child: Text(
exerciseName,
style: TextStyle(fontSize: 12, color: Colors.black),
),
),
Flexible(
fit: FlexFit.tight,
child: SizedBox(
width: 5,
)),
Flexible(
fit: FlexFit.tight,
flex: 20,
child: Text(
exercise.summary == null ? "" : exercise.summary!,
style: TextStyle(fontSize: 12, color: Colors.blue[800]),
)),
GestureDetector(
onTap: () => evaluation(exerciseRepository, exercise),
child: Badge(
elevation: 0,
padding: EdgeInsets.all(0),
position: BadgePosition.topStart(top: -5, start: -10),
animationDuration: Duration(milliseconds: 1500),
animationType: BadgeAnimationType.fade,
badgeColor: Colors.transparent,
showBadge: true,
badgeContent: /* IconButton(
iconSize: 36,
onPressed: () => showDialog(
context: context,
builder: (BuildContext context) {
return DialogCommon(
title: t("Premium function"),
descriptions: Cache().canTrial()
? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription")
: t("This is a premium function, you can reach it only with a valid subscription"),
onCancel: () => Navigator.of(context).pop(),
onTap: () => Navigator.of(context).pop(),
text: '',
);
}),
icon: */
Icon(
Icons.star,
size: 14,
color: Colors.orange[400],
),
child: Image.asset(
"asset/image/kupa.png",
width: 35,
))),
Badge(
elevation: 0,
padding: EdgeInsets.all(0),
position: BadgePosition.topStart(top: 2, start: 5),
animationDuration: Duration(milliseconds: 1500),
animationType: BadgeAnimationType.fade,
badgeColor: Colors.transparent,
showBadge: true,
badgeContent: /* Icon(
iconSize: 36,
onPressed: () => showDialog(
context: context,
builder: (BuildContext context) {
return DialogCommon(
title: t("Premium function"),
descriptions: Cache().canTrial()
? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription")
: t("This is a premium function, you can reach it only with a valid subscription"),
onCancel: () => Navigator.of(context).pop(),
onTap: () => Navigator.of(context).pop(),
text: '',
);
}), */
Icon(
Icons.star,
size: 14,
color: Colors.orange[400],
),
child: IconButton(
icon: Icon(Icons.delete, color: Colors.black12),
onPressed: () {
confirmationDialog(exerciseLogBloc, exercise);
},
)),
]),
)),
);
});
return list;
}
void evaluation(ExerciseRepository exerciseRepository, Exercise exercise) {
if (Cache().userLoggedIn != null) {
if (!Cache().hasPurchased) {
showDialog(
context: context,
builder: (BuildContext context) {
return DialogPremium(
unlocked: Cache().hasPurchased,
unlockRound: 1,
unlockedText: t("Enjoy also this premium feature to show all old evaluation data of your successful exercises."),
function: "My Exercise Logs",
onTap: () => {Navigator.of(context).pop()},
onCancel: () => {Navigator.of(context).pop()},
);
});
} else {
LinkedHashMap args = LinkedHashMap();
args['exerciseRepository'] = exerciseRepository;
args['exercise'] = exercise;
args['past'] = true;
Navigator.of(context).pushNamed('evaluationPage', arguments: args);
}
}
}
void confirmationDialog(ExerciseLogBloc bloc, Exercise exercise) {
ExerciseType? exerciseType = bloc.exerciseRepository.getExerciseTypeById(exercise.exerciseTypeId!);
String exerciseName = AppLanguage().appLocal == Locale("en") ? exerciseType!.name : exerciseType!.nameTranslation;
String strDate = AppLanguage().appLocal == Locale("en")
? "on the " + DateFormat(DateFormat.YEAR_MONTH_DAY, AppLanguage().appLocal.toString()).format(exercise.dateAdd!.toUtc())
: DateFormat(DateFormat.YEAR_MONTH_DAY, AppLanguage().appLocal.toString()).format(exercise.dateAdd!.toUtc()) + "-n";
final String unitQuantity = exercise.unitQuantity == null ? "" : "x" + exercise.unitQuantity!.toStringAsFixed(0);
showCupertinoDialog(
useRootNavigator: true,
context: context,
//barrierDismissible: false,
builder: (_) => CupertinoAlertDialog(
title: Text(t("Are you sure to delete this exercise?")),
content: Column(children: [
Divider(),
Text(
t("Exercise") + ": " + exerciseName,
style: (TextStyle(color: Colors.blue)),
),
Text(
exercise.quantity!.toStringAsFixed(0) + unitQuantity + " ",
//+
//exerciseType.unitQuantityUnit == null
// ? ""
// : exerciseType.unitQuantityUnit,
style: (TextStyle(color: Colors.deepOrange)),
),
Text(
strDate,
style: (TextStyle(color: Colors.deepOrange)),
),
]),
actions: [
TextButton(
child: Text(t("No")),
onPressed: () => Navigator.pop(context),
),
TextButton(
child: Text(t("Yes")),
onPressed: () {
Navigator.pop(context);
if (!Cache().hasPurchased) {
showDialog(
context: context,
builder: (BuildContext context) {
return DialogPremium(
unlocked: Cache().hasPurchased,
unlockRound: 1,
unlockedText: t("Enjoy also this premium fetaure to delete mistyped old exercises."),
function: "Delete Exercise",
onTap: () => {Navigator.of(context).pop()},
onCancel: () => {Navigator.of(context).pop()},
);
});
} else {
bloc.add(ExerciseLogDelete(exercise: exercise));
}
},
)
],
));
}
}
+4 -5
View File
@@ -78,7 +78,6 @@ class MyDevelopmentLog extends StatelessWidget with Trans, Common {
return MenuSearchBar(
listItems: menuBloc.menuTreeRepository.menuAsExercise,
onFind: (value) {
print("Found exercise $value");
if (value != null) {
bloc.add(TrainingLogSearch(exerciseTypeId: value.exerciseTypeId));
}
@@ -101,6 +100,7 @@ class MyDevelopmentLog extends StatelessWidget with Trans, Common {
showAgenda: true,
appointmentDisplayMode: MonthAppointmentDisplayMode.indicator,
showTrailingAndLeadingDates: true,
appointmentDisplayCount: 12,
),
appointmentTimeTextFormat: 'HH:mm',
headerDateFormat: "y MMMM",
@@ -146,7 +146,7 @@ class MyDevelopmentLog extends StatelessWidget with Trans, Common {
flex: 30,
child: Text(result.eventName,
style: GoogleFonts.inter(
fontSize: result.isExercise ? 14 : 16, color: Colors.white, fontWeight: FontWeight.bold)),
fontSize: result.isExercise ? 14 : 16, color: result.color, fontWeight: FontWeight.bold)),
),
Visibility(
visible: result.isExercise,
@@ -155,14 +155,13 @@ class MyDevelopmentLog extends StatelessWidget with Trans, Common {
flex: 25,
child: Text(
result.summary == null ? "" : result.summary!,
style: TextStyle(fontSize: 12, color: Colors.white),
style: TextStyle(fontSize: 12, color: result.color),
))),
IconButton(
padding: EdgeInsets.zero,
icon: Icon(Icons.info_outline, color: Color(0xffb4f500)),
icon: Icon(Icons.info_outline, color: result.color),
onPressed: () => result.isExercise ? evaluation(bloc.exerciseRepository, result.exercise!) : trainingEvaluation(),
),
/* */
])),
));
}),
+38 -32
View File
@@ -5,7 +5,6 @@ import 'package:aitrainer_app/library/custom_icon_icons.dart';
import 'package:aitrainer_app/model/customer_training_plan_details.dart';
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
import 'package:aitrainer_app/util/app_localization.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:aitrainer_app/widgets/app_bar.dart';
import 'package:aitrainer_app/widgets/dialog_common.dart';
@@ -515,55 +514,62 @@ class ExerciseTile extends StatelessWidget with Trans {
@override
Widget build(BuildContext context) {
setContext(context);
//bloc.setTileKey(tileKey);
//print("Display Exercise: ${detail.exerciseTypeId}");
return CarouselSlider(
options: CarouselOptions(
viewportFraction: 1,
reverse: false,
enableInfiniteScroll: false,
autoPlay: false,
aspectRatio: 1.3,
enlargeCenterPage: true,
onPageChanged: (index, reason) => {print("index changed $index")},
enlargeStrategy: CenterPageEnlargeStrategy.scale),
viewportFraction: 1,
reverse: false,
enableInfiniteScroll: false,
autoPlay: false,
aspectRatio: 1.28,
enlargeCenterPage: false,
onPageChanged: (index, reason) {
if (detail.exercises.length == 0) {
int alternateIndex = index;
if (alternateIndex >= bloc.alternatives[detail.customerTrainingPlanDetailsId].length) {
alternateIndex = 0;
}
CustomerTrainingPlanDetails? alternate = bloc.alternatives[detail.customerTrainingPlanDetailsId][alternateIndex];
if (alternate != null) {
bloc.add(TrainingPlanAlternateChange(detail: alternate, index: alternateIndex));
}
} else {
bloc.add(TrainingPlanCreateException(message: t("This exericise has already been begun")));
}
},
),
items: getExerciseTiles(detail),
);
}
List<Widget> getExerciseTiles(CustomerTrainingPlanDetails detail) {
final List<Widget> list = [];
list.add(getTile(detail));
/* if (detail.alternatives.length == 0) {
detail.alternatives = Common.getExerciseTypeAlternatives(detail.exerciseTypeId);
if (bloc.alternatives[detail.customerTrainingPlanDetailsId] != null &&
bloc.alternatives[detail.customerTrainingPlanDetailsId].length > 0) {
int index = 0;
for (CustomerTrainingPlanDetails alternative in bloc.alternatives[detail.customerTrainingPlanDetailsId]) {
final Widget widget = getTile(alternative, index);
list.add(widget);
index++;
}
}
if (detail.alternatives.length > 0) {
detail.alternatives.forEach((element) {
CustomerTrainingPlanDetails? alternative = bloc.createDetailFromExerciseType(element, detail);
if (alternative != null) {
final Widget widget = getTile(alternative);
print("Alternatives for ${detail.exerciseTypeId}: $alternative");
list.add(widget);
}
});
} */
return list;
}
Widget getTile(CustomerTrainingPlanDetails detail) {
Widget getTile(CustomerTrainingPlanDetails detail, int index) {
final CustomerTrainingPlanDetails? next = bloc.getNext();
final bool noFilter = next != null && next.exerciseTypeId == detail.exerciseTypeId;
final bool done = bloc.isAllDetailsSameExerciseFinished(detail);
final bool buddyWarning = detail.exerciseType == null ? false : detail.exerciseType!.buddyWarning;
final int step = bloc.getStep(detail);
final int highlightStep = bloc.getHighlightStep(detail);
final bool hasAlternative = detail.alternatives.length > 0;
final bool hasLeftAlternative = detail.alternatives.length > 0 && index > 0;
final bool hasRightAlternative =
detail.alternatives.length > 0 && index + 1 < bloc.alternatives[detail.customerTrainingPlanDetailsId].length;
return Container(
//key: this.tileKey,
child: ClipRect(
child: Stack(alignment: Alignment.centerRight, children: [
child: Stack(alignment: Alignment.centerRight, children: [
Stack(alignment: Alignment.centerLeft, children: [
Stack(alignment: Alignment.bottomLeft, children: [
Badge(
@@ -684,7 +690,7 @@ class ExerciseTile extends StatelessWidget with Trans {
),
),
]),
hasAlternative
hasLeftAlternative
? Positioned(
top: 50,
child: Image.asset(
@@ -695,7 +701,7 @@ class ExerciseTile extends StatelessWidget with Trans {
))
: Offstage(),
]),
hasAlternative
hasRightAlternative
? Positioned(
top: 50,
child: Transform.rotate(
@@ -709,7 +715,7 @@ class ExerciseTile extends StatelessWidget with Trans {
)),
)
: Offstage(),
])));
]));
}
void skip() {
-2
View File
@@ -112,8 +112,6 @@ class TrainingPlanExercise extends StatelessWidget with Trans {
set: detail.set,
exerciseNr: detail.exercises.length + 1,
onUnitQuantityChanged: (value) => bloc.add(TrainingPlanWeightChangeRecalculate(weight: value, detail: detail)),
//onUnitQuantityChangeUp: () => bloc.add(TrainingPlanWeightChangeUp(detail: detail)),
//onUnitQuantityChangeDown: () => bloc.add(TrainingPlanWeightChangeDown(detail: detail)),
onQuantityChanged: (value) => bloc.add(TrainingPlanRepeatsChange(repeats: value.toInt(), detail: detail)),
exerciseTypeId: detail.exerciseType!.exerciseTypeId,
originalQuantity: originalQuantity,