WT 1.1.8+1 TrainingPlan
This commit is contained in:
@@ -151,7 +151,7 @@ class AccountPage extends StatelessWidget with Trans {
|
||||
),
|
||||
devices(context, accountBloc),
|
||||
loginOut(context, accountBloc),
|
||||
getMyTrainees(context, accountBloc),
|
||||
//getMyTrainees(context, accountBloc),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,9 +141,9 @@ class _ExerciseNewPageState extends State<ExerciseNewPage> with Trans, Logging {
|
||||
unitQuantityUnit: exerciseBloc.exerciseRepository.exerciseType!.unitQuantityUnit,
|
||||
hasUnitQuantity: exerciseBloc.exerciseRepository.exerciseType!.unitQuantityUnit != null,
|
||||
onQuantityChanged: (value) {
|
||||
exerciseBloc.add(ExerciseNewQuantityChange(quantity: double.parse(value)));
|
||||
exerciseBloc.add(ExerciseNewQuantityChange(quantity: value));
|
||||
},
|
||||
onUnitQuantityChanged: (value) => exerciseBloc.add(ExerciseNewQuantityUnitChange(quantity: double.parse(value))),
|
||||
onUnitQuantityChanged: (value) => exerciseBloc.add(ExerciseNewQuantityUnitChange(quantity: value)),
|
||||
//onSubmit: () => confirmationDialog(exerciseBloc, menuBloc),
|
||||
exerciseTypeId: exerciseType.exerciseTypeId,
|
||||
)),
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/bloc/training_plan/training_plan_bloc.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/track.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:aitrainer_app/widgets/app_bar.dart';
|
||||
import 'package:aitrainer_app/widgets/bottom_nav.dart';
|
||||
import 'package:aitrainer_app/widgets/dialog_common.dart';
|
||||
import 'package:aitrainer_app/widgets/image_button.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class MyTrainingPlans extends StatelessWidget with Trans, Logging {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
setContext(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBarNav(depth: 0),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage('asset/image/WT_menu_dark.jpg'),
|
||||
fit: BoxFit.cover,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
),
|
||||
child: BlocConsumer<TrainingPlanBloc, TrainingPlanState>(
|
||||
listener: (context, state) {
|
||||
if (state is TrainingPlanError) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return DialogCommon(
|
||||
warning: true,
|
||||
title: t("Warning"),
|
||||
descriptions: t(state.message),
|
||||
text: "OK",
|
||||
onTap: () => Navigator.of(context).pushNamed("login"),
|
||||
onCancel: () => {
|
||||
Navigator.of(context).pop(),
|
||||
},
|
||||
);
|
||||
});
|
||||
} else if (state is TrainingPlanFinished) {
|
||||
Navigator.of(context).pop();
|
||||
final TrainingPlanBloc bloc = BlocProvider.of<TrainingPlanBloc>(context);
|
||||
Navigator.of(context).pushNamed("myTrainingPlanExecute", arguments: bloc);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
final TrainingPlanBloc bloc = BlocProvider.of<TrainingPlanBloc>(context);
|
||||
return ModalProgressHUD(
|
||||
child: getPrograms(bloc),
|
||||
inAsyncCall: state is TrainingPlanLoading,
|
||||
opacity: 0.5,
|
||||
color: Colors.black54,
|
||||
progressIndicator: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: BottomNavigator(bottomNavIndex: 2));
|
||||
}
|
||||
|
||||
Widget getPrograms(TrainingPlanBloc bloc) {
|
||||
return CustomScrollView(scrollDirection: Axis.vertical, slivers: [
|
||||
SliverGrid(
|
||||
delegate: SliverChildListDelegate([
|
||||
getTrainingPlan(t("My Active Training"), "asset/image/exercise_plan_execute.jpg", "",
|
||||
color: Colors.yellow[400]!, route: "myTrainingPlanExecute"),
|
||||
getTrainingPlan(t("My Custom Plan"), "asset/image/exercise_plan_custom.jpg", ""),
|
||||
getTrainingPlan(t("Training Plans for Beginners"), "asset/menu/training_plans_q_beginner.jpg", "beginner"),
|
||||
getTrainingPlan(t("Training Plans for Home"), "asset/menu/training_plans_q_home.jpg", "home"),
|
||||
getTrainingPlan(t("Training Plans Advanced"), "asset/menu/training_plans_q_advanced.jpg", "advanced"),
|
||||
getTrainingPlan(t("Training Plans for Women"), "asset/menu/training_plans_q_woman.jpg", "for_woman"),
|
||||
getTrainingPlan(t("Training Plans of Celebrities"), "asset/menu/training_plans_q_celebrities.jpg", "celebrities"),
|
||||
getTrainingPlan(t("Training Plans for Gain Strength"), "asset/menu/training_plans_q_gain_strength.jpg", "gain_strength"),
|
||||
]),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
mainAxisSpacing: 15.0,
|
||||
crossAxisSpacing: 15.0,
|
||||
childAspectRatio: 1.0,
|
||||
),
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
Widget getTrainingPlan(String name, String imageUrl, String parentName,
|
||||
{Color color = Colors.white, String route = "myTrainingPlanActivate"}) {
|
||||
double mediaWidth = MediaQuery.of(context).size.width;
|
||||
double imageWidth = (mediaWidth - 45) / 2;
|
||||
|
||||
return ImageButton(
|
||||
width: imageWidth,
|
||||
textAlignment: Alignment.topLeft,
|
||||
text: name,
|
||||
style: GoogleFonts.robotoMono(
|
||||
textStyle: TextStyle(fontSize: 14, color: color, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4))),
|
||||
image: imageUrl,
|
||||
left: 5,
|
||||
textColor: color,
|
||||
onTap: () {
|
||||
if (Cache().userLoggedIn != null) {
|
||||
if (route == "myTrainingPlanActivate") {
|
||||
HashMap<String, dynamic> args = HashMap();
|
||||
args['parentName'] = parentName;
|
||||
Navigator.of(context).pushNamed("myTrainingPlanActivate", arguments: args);
|
||||
} else {
|
||||
Navigator.of(context).pushNamed(route);
|
||||
}
|
||||
}
|
||||
},
|
||||
isLocked: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -99,9 +99,9 @@ class TestSetNew extends StatelessWidget with Trans {
|
||||
unitQuantityUnit: bloc.exerciseType.unitQuantityUnit,
|
||||
hasUnitQuantity: bloc.exerciseType.unitQuantityUnit != null,
|
||||
onQuantityChanged: (value) {
|
||||
bloc.add(TestSetNewChangeQuantity(quantity: double.parse(value)));
|
||||
bloc.add(TestSetNewChangeQuantity(quantity: value));
|
||||
},
|
||||
onUnitQuantityChanged: (value) => bloc.add(TestSetNewChangeQuantityUnit(quantity: double.parse(value))),
|
||||
onUnitQuantityChanged: (value) => bloc.add(TestSetNewChangeQuantityUnit(quantity: value)),
|
||||
exerciseTypeId: bloc.exerciseType.exerciseTypeId,
|
||||
/* onSubmit: () {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@@ -0,0 +1,483 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/bloc/menu/menu_bloc.dart';
|
||||
import 'package:aitrainer_app/bloc/training_plan/training_plan_bloc.dart';
|
||||
import 'package:aitrainer_app/library/custom_icon_icons.dart';
|
||||
import 'package:aitrainer_app/library/tree_view.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/training_plan.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/util/app_language.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:aitrainer_app/widgets/app_bar.dart';
|
||||
import 'package:aitrainer_app/widgets/dialog_common.dart';
|
||||
import 'package:aitrainer_app/widgets/menu_image.dart';
|
||||
import 'package:aitrainer_app/widgets/treeview_parent_widget.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
import 'package:flutter_html/style.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
||||
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class TrainingPlanActivatePage extends StatelessWidget with Trans {
|
||||
late String parentName;
|
||||
TrainingPlanActivatePage();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
setContext(context);
|
||||
final HashMap<String, dynamic> args = ModalRoute.of(context)!.settings.arguments as HashMap<String, dynamic>;
|
||||
parentName = args['parentName'];
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBarNav(depth: 1),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage('asset/image/WT_black_background.jpg'),
|
||||
fit: BoxFit.cover,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
),
|
||||
child: BlocConsumer<TrainingPlanBloc, TrainingPlanState>(
|
||||
listener: (context, state) {
|
||||
if (state is TrainingPlanError) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return DialogCommon(
|
||||
warning: true,
|
||||
title: t("Warning"),
|
||||
descriptions: t(state.message),
|
||||
text: "OK",
|
||||
onTap: () => Navigator.of(context).pushNamed("login"),
|
||||
onCancel: () => {
|
||||
Navigator.of(context).pop(),
|
||||
},
|
||||
);
|
||||
});
|
||||
} else if (state is TrainingPlanFinished) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed("myTrainingPlanExecute");
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
final TrainingPlanBloc bloc = BlocProvider.of<TrainingPlanBloc>(context);
|
||||
return ModalProgressHUD(
|
||||
child: getPlans(bloc),
|
||||
inAsyncCall: state is TrainingPlanLoading,
|
||||
opacity: 0.5,
|
||||
color: Colors.black54,
|
||||
progressIndicator: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getPlans(TrainingPlanBloc bloc) {
|
||||
return TreeView(
|
||||
startExpanded: false,
|
||||
children: _getTreeChildren(bloc),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _getTreeChildren(TrainingPlanBloc bloc) {
|
||||
final List<TrainingPlan> plans = bloc.trainingPlanRepository.getPlansByParent(parentName);
|
||||
final String parentTitle =
|
||||
bloc.trainingPlanRepository.parentTree != null ? bloc.trainingPlanRepository.parentTree!.nameTranslation : "";
|
||||
final String parentDescription =
|
||||
bloc.trainingPlanRepository.parentTree != null && bloc.trainingPlanRepository.parentTree!.descriptionTranslation != null
|
||||
? bloc.trainingPlanRepository.parentTree!.descriptionTranslation!
|
||||
: "";
|
||||
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(" "),
|
||||
Flexible(
|
||||
child: Text(
|
||||
parentTitle,
|
||||
maxLines: 2,
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
)),
|
||||
],
|
||||
),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
Html(
|
||||
data: parentDescription,
|
||||
//Optional parameters:
|
||||
style: {
|
||||
"p": Style(
|
||||
color: Colors.black,
|
||||
fontSize: FontSize(12),
|
||||
padding: const EdgeInsets.only(left: 20, right: 8, bottom: 4),
|
||||
),
|
||||
"strong": Style(
|
||||
color: Colors.indigo,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: FontSize(14),
|
||||
),
|
||||
"h3": Style(
|
||||
color: Colors.yellow[600],
|
||||
fontSize: FontSize(16),
|
||||
textAlign: TextAlign.center,
|
||||
padding: const EdgeInsets.all(12),
|
||||
),
|
||||
"li": Style(
|
||||
color: Colors.white,
|
||||
fontSize: FontSize(14),
|
||||
padding: const EdgeInsets.only(left: 20, bottom: 10, right: 8),
|
||||
//before: "*",
|
||||
display: Display.LIST_ITEM),
|
||||
"h2": Style(
|
||||
color: Colors.yellow[600],
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: FontSize(24),
|
||||
textAlign: TextAlign.center,
|
||||
//padding: const EdgeInsets.all(4),
|
||||
),
|
||||
"h1": Style(
|
||||
color: Colors.yellow[400],
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: FontSize.larger,
|
||||
alignment: Alignment.center,
|
||||
padding: const EdgeInsets.all(4),
|
||||
),
|
||||
},
|
||||
), //
|
||||
],
|
||||
)));
|
||||
listWidget.add(explanation);
|
||||
|
||||
plans.forEach((element) {
|
||||
listWidget.add(Container(
|
||||
margin: const EdgeInsets.only(left: 4.0),
|
||||
child: TreeViewChild(
|
||||
startExpanded: false,
|
||||
parent: TreeviewParentWidget(
|
||||
text: element.nameTranslations[AppLanguage().appLocal.toString()] != null
|
||||
? element.nameTranslations[AppLanguage().appLocal.toString()]!
|
||||
: element.name,
|
||||
fontSize: 18,
|
||||
icon: Icon(Icons.list_sharp),
|
||||
color: Colors.blue[800],
|
||||
),
|
||||
children: _getChildList(element, bloc),
|
||||
)));
|
||||
});
|
||||
|
||||
return listWidget;
|
||||
}
|
||||
|
||||
List<Widget> _getChildList(TrainingPlan plan, TrainingPlanBloc bloc) {
|
||||
List<Widget> list = [];
|
||||
|
||||
list.add(Card(
|
||||
margin: EdgeInsets.only(left: 10, top: 5),
|
||||
color: Colors.white60,
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(left: 10, right: 10),
|
||||
child: Column(children: [
|
||||
Html(
|
||||
data: plan.descriptionTranslations[AppLanguage().appLocal.toString()] != null
|
||||
? plan.descriptionTranslations[AppLanguage().appLocal.toString()]!
|
||||
: plan.description,
|
||||
//Optional parameters:
|
||||
style: {
|
||||
"p": Style(
|
||||
color: Colors.black,
|
||||
padding: const EdgeInsets.all(4),
|
||||
),
|
||||
"li": Style(
|
||||
color: Colors.white,
|
||||
//padding: const EdgeInsets.all(4),
|
||||
),
|
||||
"h2": Style(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: FontSize.larger,
|
||||
|
||||
//padding: const EdgeInsets.all(4),
|
||||
),
|
||||
"h1": Style(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: FontSize.larger,
|
||||
alignment: Alignment.center,
|
||||
padding: const EdgeInsets.all(4),
|
||||
),
|
||||
},
|
||||
),
|
||||
getPlanDetails(plan, bloc),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
onPrimary: Colors.white,
|
||||
primary: Colors.orange,
|
||||
),
|
||||
child: Text(t("Activate")),
|
||||
onPressed: () {
|
||||
if (Cache().myTrainingPlan != null) {
|
||||
showCupertinoDialog(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
builder: (_) => CupertinoAlertDialog(
|
||||
title: Text(t("You have an active Training Plan!")),
|
||||
content: Column(children: [
|
||||
Divider(),
|
||||
Text(
|
||||
t("Do you want to override it with "),
|
||||
style: (TextStyle(color: Colors.blue)),
|
||||
),
|
||||
Text(
|
||||
plan.nameTranslations[AppLanguage().appLocal.toString()]! + "?",
|
||||
style: (TextStyle(color: Colors.blue[800], fontWeight: FontWeight.bold)),
|
||||
),
|
||||
]),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(t("No")),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
TextButton(
|
||||
child: Text(t("Yes")),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
bloc.add(TrainingPlanActivate(trainingPlanId: plan.trainingPlanId));
|
||||
},
|
||||
)
|
||||
],
|
||||
));
|
||||
} else {
|
||||
bloc.add(TrainingPlanActivate(trainingPlanId: plan.trainingPlanId));
|
||||
}
|
||||
},
|
||||
)
|
||||
]),
|
||||
)));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
Widget getPlanDetails(TrainingPlan plan, TrainingPlanBloc bloc) {
|
||||
return SfDataGrid(
|
||||
headerRowHeight: 30,
|
||||
rowHeight: 45,
|
||||
source: TrainingPlanDetailSource(
|
||||
plan: plan,
|
||||
menuBloc: bloc.menuBloc,
|
||||
onWeightTap: () => {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return DialogCommon(
|
||||
title: t("Calculated Weight"),
|
||||
descriptions: t("The weight is based on your previuos tests - if they exist."),
|
||||
description2: t("If it does not exist, your very first exercise will be a test."),
|
||||
text: "OK",
|
||||
onTap: () => {
|
||||
Navigator.of(context).pop(),
|
||||
},
|
||||
onCancel: () => {
|
||||
Navigator.of(context).pop(),
|
||||
},
|
||||
);
|
||||
})
|
||||
},
|
||||
onRepeatTap: () => {
|
||||
print("Reps"),
|
||||
}),
|
||||
headerGridLinesVisibility: GridLinesVisibility.both,
|
||||
gridLinesVisibility: GridLinesVisibility.both,
|
||||
columns: [
|
||||
GridTextColumn(
|
||||
//columnWidthMode: ColumnWidthMode.lastColumnFill,
|
||||
maximumWidth: 120,
|
||||
columnName: 'exerciseImage',
|
||||
label: Container(
|
||||
color: Colors.green[50],
|
||||
padding: EdgeInsets.only(left: 8.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Exercise',
|
||||
textAlign: TextAlign.start,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridTextColumn(
|
||||
visible: false,
|
||||
columnName: 'exerciseName',
|
||||
label: Container(
|
||||
color: Colors.green[50],
|
||||
padding: EdgeInsets.symmetric(horizontal: 8.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Exercise',
|
||||
textAlign: TextAlign.start,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridTextColumn(
|
||||
maximumWidth: 40,
|
||||
columnName: 'set',
|
||||
label: Container(
|
||||
color: Colors.green[50],
|
||||
padding: EdgeInsets.symmetric(horizontal: 2.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Set',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridTextColumn(
|
||||
maximumWidth: 50,
|
||||
columnName: 'repeats',
|
||||
label: Container(
|
||||
color: Colors.green[50],
|
||||
padding: EdgeInsets.symmetric(horizontal: 2.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Reps',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridTextColumn(
|
||||
maximumWidth: 60,
|
||||
columnName: 'weight',
|
||||
label: Container(
|
||||
color: Colors.green[50],
|
||||
padding: EdgeInsets.symmetric(horizontal: 2.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Weight',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
GridTextColumn(
|
||||
maximumWidth: 50,
|
||||
columnName: 'day',
|
||||
label: Container(
|
||||
color: Colors.green[50],
|
||||
padding: EdgeInsets.symmetric(horizontal: 8.0),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Day',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TrainingPlanDetailSource extends DataGridSource {
|
||||
final TrainingPlan plan;
|
||||
final MenuBloc menuBloc;
|
||||
final VoidCallback onWeightTap;
|
||||
final VoidCallback onRepeatTap;
|
||||
TrainingPlanDetailSource({
|
||||
required this.plan,
|
||||
required this.menuBloc,
|
||||
required this.onWeightTap,
|
||||
required this.onRepeatTap,
|
||||
}) {
|
||||
if (plan.details != null) {
|
||||
dataGridRows = plan.details!.map((dataGridRow) {
|
||||
WorkoutMenuTree? menuTree = menuBloc.menuTreeRepository.getMenuItemByExerciseTypeId(dataGridRow.exerciseTypeId);
|
||||
if (menuTree == null) {
|
||||
return DataGridRow(cells: []);
|
||||
}
|
||||
return DataGridRow(cells: [
|
||||
DataGridCell<Widget>(
|
||||
columnName: 'exerciseImage',
|
||||
value: MenuImage(
|
||||
imageName: menuTree.imageName,
|
||||
workoutTreeId: menuTree.id,
|
||||
radius: 8,
|
||||
)),
|
||||
DataGridCell<String>(columnName: 'exerciseName', value: menuTree.name),
|
||||
DataGridCell<int>(columnName: 'set', value: dataGridRow.set),
|
||||
DataGridCell<int>(columnName: 'reps', value: dataGridRow.repeats),
|
||||
DataGridCell<double>(columnName: 'weight', value: dataGridRow.weight),
|
||||
DataGridCell<String>(columnName: 'day', value: dataGridRow.day),
|
||||
]);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
List<DataGridRow> dataGridRows = [];
|
||||
|
||||
@override
|
||||
List<DataGridRow> get rows => dataGridRows;
|
||||
|
||||
@override
|
||||
DataGridRowAdapter? buildRow(DataGridRow row) {
|
||||
if (row.getCells().isEmpty) {
|
||||
return null;
|
||||
}
|
||||
String name = row.getCells()[1].value;
|
||||
return DataGridRowAdapter(
|
||||
color: Colors.white60,
|
||||
cells: row.getCells().map<Widget>((dataGridCell) {
|
||||
return Container(
|
||||
alignment: dataGridCell.columnName == "exerciseImage" ? Alignment.centerLeft : Alignment.centerLeft,
|
||||
padding: EdgeInsets.only(top: 2, bottom: 2, left: 4, right: 4),
|
||||
child: dataGridCell.columnName == "exerciseImage"
|
||||
? Stack(alignment: AlignmentDirectional.bottomStart, children: [
|
||||
dataGridCell.value,
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 4, right: 8, bottom: 3),
|
||||
child: Text(
|
||||
name,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style:
|
||||
GoogleFonts.inter(fontSize: 10, color: Colors.yellow[600], fontWeight: FontWeight.bold, shadows: <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(2.0, 2.0),
|
||||
blurRadius: 6.0,
|
||||
color: Colors.black,
|
||||
),
|
||||
]),
|
||||
))
|
||||
])
|
||||
: dataGridCell.columnName == "weight" && dataGridCell.value == -1
|
||||
? GestureDetector(
|
||||
onTap: () {
|
||||
onWeightTap();
|
||||
},
|
||||
child: Icon(
|
||||
CustomIcon.question_circle,
|
||||
color: Colors.indigo[300],
|
||||
))
|
||||
: dataGridCell.columnName == "reps" && dataGridCell.value == -1
|
||||
? GestureDetector(
|
||||
onTap: () {
|
||||
onRepeatTap();
|
||||
},
|
||||
child: Icon(
|
||||
CustomIcon.question_circle,
|
||||
color: Colors.indigo[600],
|
||||
))
|
||||
: Text(dataGridCell.value.toString(),
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
color: Colors.indigo,
|
||||
fontWeight: FontWeight.bold,
|
||||
)));
|
||||
}).toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,510 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/bloc/training_plan/training_plan_bloc.dart';
|
||||
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/trans.dart';
|
||||
import 'package:aitrainer_app/widgets/app_bar.dart';
|
||||
import 'package:aitrainer_app/widgets/dialog_common.dart';
|
||||
import 'package:aitrainer_app/widgets/menu_image.dart';
|
||||
import 'package:ezanimation/ezanimation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
||||
import 'package:timeline_tile/timeline_tile.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class TrainingPlanExecutePage extends StatelessWidget with Trans {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TrainingPlanBloc bloc = BlocProvider.of<TrainingPlanBloc>(context);
|
||||
setContext(context);
|
||||
return Scaffold(
|
||||
appBar: AppBarNav(depth: 0),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage('asset/image/WT_black_background.jpg'),
|
||||
fit: BoxFit.cover,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
),
|
||||
child: BlocConsumer<TrainingPlanBloc, TrainingPlanState>(listener: (context, state) {
|
||||
if (state is TrainingPlanError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
|
||||
} else if (state is TrainingPlanFinished) {}
|
||||
}, builder: (context, state) {
|
||||
return ModalProgressHUD(
|
||||
child: getExercises(bloc),
|
||||
inAsyncCall: state is TrainingPlanLoading,
|
||||
opacity: 0.5,
|
||||
color: Colors.black54,
|
||||
progressIndicator: CircularProgressIndicator(),
|
||||
);
|
||||
}),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => bloc.getNext() != null ? executeExercise(bloc, bloc.getNext()!) : Navigator.of(context).pushNamed('home'),
|
||||
backgroundColor: Colors.orange[800],
|
||||
icon: Icon(CustomIcon.weight_hanging),
|
||||
label: Text(
|
||||
t("Training!"),
|
||||
style: GoogleFonts.inter(fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getExercises(TrainingPlanBloc bloc) {
|
||||
return CustomScrollView(slivers: [
|
||||
SliverList(delegate: SliverChildListDelegate(getTiles(bloc))),
|
||||
]);
|
||||
}
|
||||
|
||||
List<Widget> getTiles(TrainingPlanBloc bloc) {
|
||||
List<Widget> tiles = [];
|
||||
tiles.add(getStartTile(bloc));
|
||||
tiles.addAll(getExerciseTiles(bloc, context));
|
||||
if (bloc.myPlan != null) tiles.add(getEndTile());
|
||||
return tiles;
|
||||
}
|
||||
|
||||
Widget getStartTile(TrainingPlanBloc bloc) {
|
||||
String startText = "";
|
||||
String explainingText = "";
|
||||
if (null == bloc.getMyPlan()) {
|
||||
startText = "No Active Training Plan";
|
||||
explainingText = "Please select one in the Training menu, or create your custom plan";
|
||||
} else {
|
||||
startText = bloc.isStarted() ? "Continue your training" : "Start your training";
|
||||
explainingText = bloc.getMyPlan()!.name != null ? bloc.getMyPlan()!.name! : "";
|
||||
}
|
||||
|
||||
return TimelineTile(
|
||||
alignment: TimelineAlign.manual,
|
||||
lineXY: 0.1,
|
||||
isFirst: true,
|
||||
afterLineStyle: const LineStyle(
|
||||
color: Colors.orange,
|
||||
thickness: 6,
|
||||
),
|
||||
indicatorStyle: IndicatorStyle(
|
||||
width: 40,
|
||||
color: Colors.orange,
|
||||
padding: const EdgeInsets.all(8),
|
||||
iconStyle: IconStyle(
|
||||
color: Colors.white,
|
||||
iconData: Icons.emoji_flags_rounded,
|
||||
),
|
||||
),
|
||||
endChild: Container(
|
||||
padding: EdgeInsets.only(top: 30),
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 120,
|
||||
),
|
||||
color: Colors.transparent,
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: startText,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.yellow[400],
|
||||
shadows: <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(5.0, 5.0),
|
||||
blurRadius: 12.0,
|
||||
color: Colors.black54,
|
||||
),
|
||||
Shadow(
|
||||
offset: Offset(-3.0, 3.0),
|
||||
blurRadius: 12.0,
|
||||
color: Colors.black54,
|
||||
),
|
||||
],
|
||||
)),
|
||||
TextSpan(
|
||||
text: "\n",
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 16,
|
||||
color: Colors.white,
|
||||
)),
|
||||
TextSpan(
|
||||
text: explainingText,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 16,
|
||||
color: Colors.white,
|
||||
)),
|
||||
])),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getEndTile() {
|
||||
return Container(
|
||||
color: Colors.transparent,
|
||||
child: TimelineTile(
|
||||
alignment: TimelineAlign.manual,
|
||||
lineXY: 0.1,
|
||||
isLast: true,
|
||||
beforeLineStyle: const LineStyle(
|
||||
color: Colors.orange,
|
||||
thickness: 6,
|
||||
),
|
||||
indicatorStyle: IndicatorStyle(
|
||||
width: 40,
|
||||
color: Colors.orange,
|
||||
padding: const EdgeInsets.all(8),
|
||||
iconStyle: IconStyle(
|
||||
color: Colors.white,
|
||||
iconData: Icons.thumb_up,
|
||||
),
|
||||
),
|
||||
endChild: Container(
|
||||
padding: EdgeInsets.only(top: 50),
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 120,
|
||||
),
|
||||
color: Colors.transparent,
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: "Finish!",
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.yellow[400],
|
||||
shadows: <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(5.0, 5.0),
|
||||
blurRadius: 12.0,
|
||||
color: Colors.black54,
|
||||
),
|
||||
Shadow(
|
||||
offset: Offset(-3.0, 3.0),
|
||||
blurRadius: 12.0,
|
||||
color: Colors.black54,
|
||||
),
|
||||
],
|
||||
)),
|
||||
])),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getExerciseTiles(TrainingPlanBloc bloc, BuildContext context) {
|
||||
List<Widget> tiles = [];
|
||||
if (bloc.myPlan != null && bloc.myPlan!.details.isNotEmpty) {
|
||||
bloc.myPlan!.details.forEach((element) {
|
||||
tiles.add(GestureDetector(
|
||||
onTap: () => {},
|
||||
child: ExerciseTile(
|
||||
bloc: bloc,
|
||||
detail: element,
|
||||
)));
|
||||
});
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
void executeExercise(TrainingPlanBloc bloc, CustomerTrainingPlanDetails detail) {
|
||||
CustomerTrainingPlanDetails? next = bloc.getNext();
|
||||
|
||||
if (next != null) {
|
||||
String title = "";
|
||||
String description = "";
|
||||
String description2 = "";
|
||||
if (next.exerciseTypeId != detail.exerciseTypeId) {
|
||||
title = t("Stop!");
|
||||
description = t("Please continue with the next exercise in the queue:") + next.exerciseType!.nameTranslation;
|
||||
description2 = t("Or, you can redifine this exercise queue in the Compact Test menu");
|
||||
} else {
|
||||
final HashMap args = HashMap();
|
||||
args['exerciseType'] = next.exerciseType;
|
||||
args['customerTrainingPlanDetails'] = detail;
|
||||
Navigator.of(context).pushNamed('myTrainingPlanExercise', arguments: args);
|
||||
return;
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return DialogCommon(
|
||||
title: title,
|
||||
descriptions: description,
|
||||
description2: description2,
|
||||
text: "OK",
|
||||
onTap: () => {Navigator.of(context).pop()},
|
||||
onCancel: () => {Navigator.of(context).pop()},
|
||||
);
|
||||
});
|
||||
} else {
|
||||
Navigator.of(context).pushNamed('home');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class ExerciseTile extends StatefulWidget with Trans {
|
||||
final TrainingPlanBloc bloc;
|
||||
final CustomerTrainingPlanDetails detail;
|
||||
|
||||
ExerciseTile({required this.bloc, required this.detail});
|
||||
|
||||
@override
|
||||
_ExerciseTileState createState() => _ExerciseTileState();
|
||||
}
|
||||
|
||||
class _ExerciseTileState extends State<ExerciseTile> with Trans {
|
||||
final EzAnimation animation = EzAnimation(1.0, 30.0, Duration(seconds: 3), reverseCurve: Curves.easeIn);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
animation.start();
|
||||
animation.addStatusListener((status) {
|
||||
if (status == AnimationStatus.completed) {}
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
bool didUpdateWidget(ExerciseTile oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
Future.delayed(Duration(milliseconds: 400)).then((value) => animation.start());
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget getIndicator(ExercisePlanDetailState state) {
|
||||
CustomerTrainingPlanDetails? next = widget.bloc.getNext();
|
||||
bool actual = false;
|
||||
if (next != null) {
|
||||
if (next.exerciseTypeId == widget.detail.exerciseTypeId) {
|
||||
actual = true;
|
||||
}
|
||||
}
|
||||
if (state.equalsTo(ExercisePlanDetailState.inProgress)) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
child: Container(
|
||||
color: actual ? Colors.green : Colors.orange,
|
||||
child: Icon(
|
||||
CustomIcon.calendar_2,
|
||||
size: 28,
|
||||
color: Colors.white,
|
||||
)));
|
||||
} else if (state.equalsTo(ExercisePlanDetailState.finished)) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
child: Icon(
|
||||
CustomIcon.ok_circled,
|
||||
size: 40,
|
||||
color: Colors.green,
|
||||
)));
|
||||
} else {
|
||||
return Image.asset(
|
||||
"asset/image/pict_reps_volumen_db.png",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
setContext(context);
|
||||
final ExercisePlanDetailState state = widget.detail.state;
|
||||
final bool done = state.equalsTo(ExercisePlanDetailState.finished);
|
||||
final String countSerie = widget.detail.set.toString();
|
||||
final String step = (widget.detail.exercises.length).toString();
|
||||
String weight = widget.detail.weight!.toStringAsFixed(1);
|
||||
String restingTime = widget.detail.restingTime == null ? "" : widget.detail.restingTime!.toStringAsFixed(0);
|
||||
bool isTest = false;
|
||||
if (widget.detail.weight! == -1) {
|
||||
weight = t("TEST");
|
||||
isTest = true;
|
||||
}
|
||||
setContext(context);
|
||||
return Container(
|
||||
color: Colors.transparent,
|
||||
child: TimelineTile(
|
||||
alignment: TimelineAlign.manual,
|
||||
lineXY: 0.1,
|
||||
beforeLineStyle: const LineStyle(
|
||||
color: Color(0xffb4f500),
|
||||
thickness: 6,
|
||||
),
|
||||
afterLineStyle: const LineStyle(
|
||||
color: Color(0xffb4f500),
|
||||
thickness: 6,
|
||||
),
|
||||
indicatorStyle: IndicatorStyle(
|
||||
width: 40,
|
||||
height: 40,
|
||||
indicator: getIndicator(state),
|
||||
),
|
||||
endChild: Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Row(children: [
|
||||
Container(
|
||||
width: 120,
|
||||
height: 80,
|
||||
child: MenuImage(
|
||||
imageName: widget.bloc.getActualImageName(widget.detail.exerciseType!.exerciseTypeId),
|
||||
workoutTreeId: widget.bloc.getActualWorkoutTreeId(widget.detail.exerciseType!.exerciseTypeId)!,
|
||||
)),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Expanded(
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: done ? Colors.grey[400] : Colors.white,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: widget.detail.exerciseType!.nameTranslation,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: done ? Colors.grey[400] : Colors.orange[500],
|
||||
shadows: <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(5.0, 5.0),
|
||||
blurRadius: 12.0,
|
||||
color: Colors.black54,
|
||||
),
|
||||
Shadow(
|
||||
offset: Offset(-3.0, 3.0),
|
||||
blurRadius: 12.0,
|
||||
color: Colors.black54,
|
||||
),
|
||||
],
|
||||
)),
|
||||
widget.detail.exerciseType!.unitQuantityUnit != null
|
||||
? TextSpan(
|
||||
text: "\n",
|
||||
)
|
||||
: TextSpan(),
|
||||
widget.detail.exerciseType!.unitQuantityUnit != null
|
||||
? TextSpan(
|
||||
text: t(widget.detail.exerciseType!.unitQuantityUnit!) + ": ",
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12, color: done ? Colors.grey[100] : Colors.yellow[400], fontWeight: FontWeight.bold))
|
||||
: TextSpan(),
|
||||
widget.detail.exerciseType!.unitQuantityUnit != null
|
||||
? TextSpan(
|
||||
text: weight,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12,
|
||||
))
|
||||
: TextSpan(),
|
||||
TextSpan(
|
||||
text: "\n",
|
||||
),
|
||||
TextSpan(
|
||||
text: t(widget.detail.exerciseType!.unit) + ": ",
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12, color: done ? Colors.grey[100] : Colors.yellow[400], fontWeight: FontWeight.bold)),
|
||||
TextSpan(
|
||||
text: widget.detail.repeats!.toString(),
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12,
|
||||
)),
|
||||
TextSpan(
|
||||
text: "\n",
|
||||
),
|
||||
TextSpan(
|
||||
text: t("Set") + ": ",
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12, color: done ? Colors.grey[100] : Colors.yellow[400], fontWeight: FontWeight.bold)),
|
||||
TextSpan(
|
||||
text: step + "/" + countSerie,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12,
|
||||
)),
|
||||
TextSpan(
|
||||
text: "\n",
|
||||
),
|
||||
TextSpan(
|
||||
text: t("Resting time") + ": ",
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12, color: done ? Colors.grey[100] : Colors.yellow[400], fontWeight: FontWeight.bold)),
|
||||
TextSpan(
|
||||
text: restingTime + " " + t("min(s)"),
|
||||
style: GoogleFonts.inter(fontSize: 12, color: done ? Colors.grey[100] : Colors.white, fontWeight: FontWeight.bold)),
|
||||
]),
|
||||
)),
|
||||
done
|
||||
? AnimatedBuilder(
|
||||
animation: animation,
|
||||
builder: (context, snapshot) {
|
||||
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
Image.asset(
|
||||
"asset/image/kupa.png",
|
||||
width: animation.value,
|
||||
),
|
||||
Text("Result", style: GoogleFonts.inter(fontSize: 10, color: Colors.white)),
|
||||
]);
|
||||
})
|
||||
: Offstage(),
|
||||
isTest
|
||||
? AnimatedBuilder(
|
||||
animation: animation,
|
||||
builder: (context, snapshot) {
|
||||
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
GestureDetector(
|
||||
onTap: () => showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return DialogCommon(
|
||||
warning: false,
|
||||
title: t("Why Test?"),
|
||||
descriptions: t("This is your first exercise after at least 3 weeks."),
|
||||
description2:
|
||||
t("The first exercise will be a test. The following sets will be recalculated base on your test."),
|
||||
description3: t("This is the most optimal way for your development"),
|
||||
text: "OK",
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
onCancel: () => {
|
||||
Navigator.of(context).pop(),
|
||||
},
|
||||
);
|
||||
}),
|
||||
child: Icon(
|
||||
CustomIcon.question_circle,
|
||||
color: Colors.yellowAccent[700],
|
||||
size: 16,
|
||||
)),
|
||||
]);
|
||||
})
|
||||
: Offstage()
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/bloc/test_set_control/test_set_control_bloc.dart';
|
||||
import 'package:aitrainer_app/bloc/test_set_execute/test_set_execute_bloc.dart';
|
||||
import 'package:aitrainer_app/bloc/test_set_new/test_set_new_bloc.dart';
|
||||
import 'package:aitrainer_app/bloc/training_plan/training_plan_bloc.dart';
|
||||
import 'package:aitrainer_app/library/custom_icon_icons.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer_training_plan_details.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:aitrainer_app/widgets/app_bar.dart';
|
||||
import 'package:aitrainer_app/widgets/bottom_bar_multiple_exercises.dart';
|
||||
import 'package:aitrainer_app/widgets/exercise_save.dart';
|
||||
import 'package:aitrainer_app/widgets/number_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class TrainingPlanExercise extends StatelessWidget with Trans {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final HashMap args = ModalRoute.of(context)!.settings.arguments as HashMap;
|
||||
final ExerciseType exerciseType = args['exerciseType'];
|
||||
final CustomerTrainingPlanDetails detail = args['customerTrainingPlanDetails'];
|
||||
// ignore: close_sinks
|
||||
final TrainingPlanBloc bloc = BlocProvider.of<TrainingPlanBloc>(context);
|
||||
|
||||
setContext(context);
|
||||
return Scaffold(
|
||||
appBar: AppBarNav(depth: 1),
|
||||
body: Container(
|
||||
height: double.infinity,
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: Cache().userLoggedIn!.sex == "m"
|
||||
? AssetImage("asset/image/WT_black_background.jpg")
|
||||
: AssetImage("asset/image/WT_Results_for_female.jpg"),
|
||||
fit: BoxFit.cover,
|
||||
alignment: Alignment.center,
|
||||
),
|
||||
),
|
||||
child: BlocConsumer<TrainingPlanBloc, TrainingPlanState>(listener: (context, state) {
|
||||
if (state is TrainingPlanError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
|
||||
}
|
||||
}, builder: (context, state) {
|
||||
return ModalProgressHUD(
|
||||
child: getExercises(bloc, detail),
|
||||
inAsyncCall: state is TrainingPlanLoading,
|
||||
opacity: 0.5,
|
||||
color: Colors.black54,
|
||||
progressIndicator: CircularProgressIndicator(),
|
||||
);
|
||||
}),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => {
|
||||
Navigator.of(context).pop(),
|
||||
bloc.add(TrainingPlanSaveExercise(detail: detail)),
|
||||
},
|
||||
backgroundColor: Colors.orange[800],
|
||||
icon: Icon(CustomIcon.save),
|
||||
label: Text(
|
||||
t("Save"),
|
||||
style: GoogleFonts.inter(fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
),
|
||||
/* bottomNavigationBar: BottomBarMultipleExercises(
|
||||
//isSet: executeBloc.miniTestSet == true,
|
||||
exerciseTypeId: exerciseType.exerciseTypeId,
|
||||
), */
|
||||
);
|
||||
}
|
||||
|
||||
Widget getExercises(TrainingPlanBloc bloc, CustomerTrainingPlanDetails detail) {
|
||||
final String noTestTextWithWeight = "Please try to execute this exercise with exact weight and repeats what is suggested";
|
||||
final String noTestTextNoWeight = "Please try to execute this exercise with exact repeats what is suggested";
|
||||
return ExerciseSave(
|
||||
exerciseName: detail.exerciseType!.nameTranslation,
|
||||
exerciseDescription: detail.exerciseType!.descriptionTranslation,
|
||||
exerciseTask: detail.exerciseType!.unitQuantityUnit != null
|
||||
? detail.weight == -1
|
||||
? t("Please take a relative bigger weight and repeat 12-20 times and do your best! MAXIMIZE it!")
|
||||
: noTestTextWithWeight
|
||||
: detail.repeats == -1
|
||||
? t("Please repeat as much times as you can! MAXIMIZE it!")
|
||||
: noTestTextNoWeight,
|
||||
unit: detail.exerciseType!.unit,
|
||||
unitQuantityUnit: detail.exerciseType!.unitQuantityUnit,
|
||||
hasUnitQuantity: detail.exerciseType!.unitQuantityUnit != null,
|
||||
weight: detail.weight == -1 ? 30 : detail.weight,
|
||||
repeats: detail.repeats == -1 ? 12 : detail.repeats,
|
||||
onUnitQuantityChanged: (value) => bloc.add(TrainingPlanWeightChange(weight: value, detail: detail)),
|
||||
onQuantityChanged: (value) => bloc.add(TrainingPlanRepeatsChange(repeats: value.toInt(), detail: detail)),
|
||||
exerciseTypeId: detail.exerciseType!.exerciseTypeId,
|
||||
);
|
||||
}
|
||||
|
||||
Widget getExerciseForm(TrainingPlanBloc bloc, CustomerTrainingPlanDetails detail) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(top: 10, left: 25, right: 25),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
detail.exerciseType!.nameTranslation,
|
||||
style: GoogleFonts.archivoBlack(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 24,
|
||||
color: Colors.white,
|
||||
shadows: <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(2.0, 2.0),
|
||||
blurRadius: 6.0,
|
||||
color: Colors.black54,
|
||||
),
|
||||
Shadow(
|
||||
offset: Offset(-3.0, 3.0),
|
||||
blurRadius: 12.0,
|
||||
color: Colors.black54,
|
||||
),
|
||||
],
|
||||
),
|
||||
overflow: TextOverflow.fade,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
softWrap: true,
|
||||
),
|
||||
Divider(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
Divider(),
|
||||
detail.weight != -1 ? numberPickForm(bloc, detail) : numberPickForm(bloc, detail),
|
||||
],
|
||||
)));
|
||||
}
|
||||
|
||||
Widget numberPickForm(TrainingPlanBloc bloc, CustomerTrainingPlanDetails detail) {
|
||||
final String strTimes = detail.repeats!.toStringAsFixed(1); // : "maximum";
|
||||
|
||||
List<Widget> listWidgets = [
|
||||
GestureDetector(
|
||||
onTap: () => {},
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.normal,
|
||||
color: Colors.yellow[300],
|
||||
),
|
||||
children: [
|
||||
TextSpan(text: t("Please repeat with ")),
|
||||
TextSpan(
|
||||
text: detail.weight!.toStringAsFixed(1) + " " + detail.exerciseType!.unitQuantityUnit!,
|
||||
style: GoogleFonts.inter(
|
||||
decoration: TextDecoration.underline,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.yellow[100],
|
||||
),
|
||||
),
|
||||
TextSpan(text: t("hu_with") + " "),
|
||||
TextSpan(
|
||||
text: strTimes + " ",
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.yellow[100],
|
||||
)),
|
||||
TextSpan(
|
||||
text: t(
|
||||
"times!",
|
||||
)),
|
||||
]),
|
||||
)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
NumberPickerWidget(
|
||||
minValue: 0,
|
||||
maxValue: 200,
|
||||
initalValue: detail.repeats!,
|
||||
unit: t("reps"),
|
||||
color: Colors.yellow[50]!,
|
||||
onChange: (value) => {}),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
padding: EdgeInsets.all(0),
|
||||
primary: Colors.white,
|
||||
onSurface: Colors.blueAccent,
|
||||
),
|
||||
onPressed: () => {},
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Image.asset('asset/icon/gomb_orange_c.png', width: 140, height: 60),
|
||||
Text(
|
||||
t("Save"),
|
||||
style: TextStyle(fontSize: 16, color: Colors.white),
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: listWidgets,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user