Merge ssh://git.aitrainer.app:6622/bossanyit/aitrainer_app

This commit is contained in:
Tibor Bossanyi
2020-09-16 16:14:44 +02:00
55 changed files with 2837 additions and 1220 deletions
+67 -85
View File
@@ -1,5 +1,7 @@
import 'package:aitrainer_app/bloc/account/account_bloc.dart';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/customer.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:aitrainer_app/widgets/bottom_nav.dart';
import 'package:flutter/material.dart';
@@ -7,6 +9,7 @@ import 'package:flutter/cupertino.dart';
// ignore: must_be_immutable
class AccountPage extends StatelessWidget {
// ignore: close_sinks
AccountBloc accountBloc;
@override
@@ -93,7 +96,7 @@ class AccountPage extends StatelessWidget {
),
),
loginOut( context, accountBloc ),
//exercises(exerciseChangingViewModel),
getMyTrainees(context, accountBloc),
]);
}
@@ -137,93 +140,72 @@ class AccountPage extends StatelessWidget {
return element;
}
/* ListTile exercises( ExerciseChangingViewModel model ) {
ListTile element = ListTile();
if ( Auth().userLoggedIn == null ) {
return element;
Widget getMyTrainees( BuildContext context, AccountBloc accountBloc ) {
if ( accountBloc.customerRepository.customer == null ) {
return Container();
}
element = ListTile(
title: Text(AppLocalizations.of(context).translate("Exercises")),
subtitle: Column(
children: [
FutureBuilder<List<ExerciseViewModel>>(
future: _exercises,
builder: (context, snapshot) {
if (snapshot.hasData) {
return getExercises( model );//CustomerListWidget(customers: _exerciseViewModel.exerciseList);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
// By default, show a loading spinner.
return CircularProgressIndicator();
}
),]
));
return element;
}
*/
/*
Widget getExercises( ExerciseChangingViewModel model ) {
List<ExerciseViewModel> exercises = model.exerciseList;
Column element = Column();
if (exercises.length > 0) {
List<Column> rows = List();
exercises.forEach((exercise) {
String exerciseName = AppLocalizations.of(context).translate(
Common.getExerciseType(exercise.getExercise().exerciseTypeId).name);
String quantity = exercise.getExercise().quantity.toString() + " " +
AppLocalizations.of(context).translate(exercise.getExercise().unit);
String unitQuantity = "";
String unitQuantityUnit = "";
String date = Common.getDateLocale(exercise.getExercise().dateAdd, false);
if (exercise.getExercise().unitQuantity != null) {
unitQuantity = exercise.getExercise().unitQuantity.toString();
unitQuantityUnit = AppLocalizations.of(context).translate(
Common.getExerciseType(exercise.getExercise().exerciseTypeId).unitQuantityUnit);
}
TableRow row = TableRow(
children: [
Text(date),
Text(exerciseName),
Text(quantity),
Text(unitQuantity + " " + unitQuantityUnit),
]
);
Table table = Table(
defaultColumnWidth: FractionColumnWidth(0.28),
children: [row],
);
Column col = Column(
children: [
table,
Row(
children: [
Text(" "),
]
)
],
);
rows.add(col);
});
element = Column(
children: rows,
if ( accountBloc.customerRepository.customer.trainer == 0 ) {
return ListTile(
title: Container(),
);
}
return element;
if (accountBloc.customerRepository.getTraineesList() == null ) {
return ListTile(
leading: Icon(Icons.people),
title: RaisedButton(
color: Colors.white70,
onPressed: () => accountBloc.add(AccountGetTrainees()),
child: Text("See my trainees"),
),
);
}
List<Widget> elements = List<Widget>();
accountBloc.customerRepository.getTraineesList().forEach((element) {
Customer trainee = element;
String name = trainee.name;
String firstName = trainee.firstname;
String nodeName = AppLanguage().appLocal == Locale("en") ?
firstName + " " + name : name + " " + firstName;
bool selected = accountBloc.traineeId == trainee.customerId;
Widget widget = FlatButton(
padding: EdgeInsets.all(10),
shape:RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
side: BorderSide(width: 2, color: selected ? Colors.blue : Colors.black26 ),
),
onPressed: () {
accountBloc.add(AccountSelectTrainee(traineeId: trainee.customerId));
//Navigator.of(context).pushNamed('login');
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(nodeName, style:
TextStyle(
color: selected ? Colors.blue : Colors.black54,
fontWeight: selected ? FontWeight.bold : FontWeight.normal
),
),
Icon(Icons.arrow_forward_ios),
]),
);
elements.add(widget);
});
return ListTile(
leading: Icon(Icons.people),
subtitle: Text("My Trainees"),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: elements,
)
);
}
} */
}
+241
View File
@@ -0,0 +1,241 @@
import 'dart:collection';
import 'package:aitrainer_app/bloc/exercise_add_by_plan_bloc.dart';
import 'package:aitrainer_app/bloc/exercise_by_plan/exercise_by_plan_bloc.dart';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/model/workout_tree.dart';
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/widgets/splash.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
class ExerciseAddByPlanPage extends StatefulWidget{
_ExerciseAddByPlanPage createState() => _ExerciseAddByPlanPage();
}
class _ExerciseAddByPlanPage extends State<ExerciseAddByPlanPage> {
@override
Widget build(BuildContext context) {
LinkedHashMap arguments = ModalRoute.of(context).settings.arguments;
// ignore: close_sinks
final ExerciseByPlanBloc bloc = arguments['blocExerciseByPlan'];
final int customerId = arguments['customerId'];
final WorkoutTree workoutTree = arguments['workoutTree'];
final ExerciseRepository exerciseRepository = ExerciseRepository();
return BlocProvider(
create: (context) =>
ExerciseAddByPlanFormBloc(
exerciseRepository: exerciseRepository,
exercisePlanRepository: bloc.exercisePlanRepository,
customerId: customerId,
workoutTree: workoutTree),
child: BlocBuilder<ExerciseAddByPlanFormBloc, FormBlocState>(
builder: (context, state) {
// ignore: close_sinks
final exerciseBloc = BlocProvider.of<ExerciseAddByPlanFormBloc>(context);
if ( state is FormBlocLoading ) {
return LoadingDialog();
} else if ( state is FormBlocSuccess) {
return getControlForm(exerciseBloc);
} else {
return getControlForm(exerciseBloc);
}
}
));
}
Form getControlForm( ExerciseAddByPlanFormBloc exerciseBloc) {
String exerciseName = AppLanguage().appLocal == Locale("en") ?
exerciseBloc.exerciseRepository.exerciseType.name :
exerciseBloc.exerciseRepository.exerciseType.nameTranslation;
return Form(
autovalidate: true,
child: Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
backgroundColor: Colors.black,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Add Exercise"),
Image.asset(
'asset/image/WT_long_logo.png',
fit: BoxFit.cover,
height: 65.0,
),
],
),
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
),
),
body: Container(
width: MediaQuery
.of(context)
.size
.width,
height: MediaQuery
.of(context)
.size
.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.png'),
fit: BoxFit.fill,
alignment: Alignment.center,
),
),
child: Container(
padding: const EdgeInsets.only (top: 25, left: 25, right: 25),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text(exerciseName,
style: TextStyle(fontWeight: FontWeight.bold,
fontSize: 18,
color: Colors.deepOrange),
overflow: TextOverflow.fade,
maxLines: 1,
softWrap: true,
),
Divider(color: Colors.transparent,),
Divider(),
Column(
children: repeatExercises(exerciseBloc),
),
Divider(),
]),
)
)
),
),
);
}
List<Column> repeatExercises(ExerciseAddByPlanFormBloc exerciseBloc) {
List<Column> listColumns = List<Column>();
for ( int i = 0; i < exerciseBloc.countSteps; i++) {
Column col = Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Divider(color: Colors.transparent,),
Text("Execute the " + (i+1).toString() + ". set!",
style: TextStyle(),),
TextFieldBlocBuilder(
readOnly: exerciseBloc.step != i+1,
textFieldBloc: exerciseBloc.quantity1Field,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
color: Colors.deepOrange,
fontWeight: FontWeight.bold),
inputFormatters: [
WhitelistingTextInputFormatter(RegExp(r"[\d.]"))
],
decoration: InputDecoration(
fillColor: Colors.white,
filled: false,
hintStyle: TextStyle(
fontSize: 12, color: Colors.black54, fontWeight: FontWeight.w100),
hintText: AppLocalizations.of(context)
.translate("The number of the exercise"),
labelStyle: TextStyle(fontSize: 12, color: Colors.deepOrange, fontWeight: FontWeight.normal),
labelText: "Please repeat with " + exerciseBloc.unitQuantity1Field.value + " " +
exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit + " " +
exerciseBloc.exercisePlanRepository.actualPlanDetail.repeats.toString() + " times!",
),
),
TextFieldBlocBuilder(
readOnly: exerciseBloc.step != i+1,
textFieldBloc: exerciseBloc.unitQuantity1Field,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,
color: Colors.black54,
fontWeight: FontWeight.bold),
inputFormatters: [
WhitelistingTextInputFormatter(RegExp(r"[\d.]"))
],
decoration: InputDecoration(
fillColor: Colors.white,
filled: false,
hintStyle: TextStyle(
fontSize: 12, color: Colors.black54, fontWeight: FontWeight.w100),
labelStyle: TextStyle(fontSize: 12, color: Colors.deepOrange, fontWeight: FontWeight.normal),
labelText: exerciseBloc.exerciseRepository.exerciseType.unitQuantityUnit,
),
),
RaisedButton(
padding: EdgeInsets.all(0),
textColor: Colors.white,
color: exerciseBloc.step == i+1 ? Colors.blue : Colors.black26,
focusColor: Colors.blueAccent,
onPressed: () =>
{
print ("Submit step " + exerciseBloc.step.toString() + " (i) " + i.toString()),
if ( exerciseBloc.step == i+1 ) {
exerciseBloc.submit()
},
if ( i+1 == exerciseBloc.countSteps) {
Navigator.of(context).pop()
}
},
child: Text(
AppLocalizations.of(context).translate("Check"),
style: TextStyle(fontSize: 12),)
),
Divider(color: Colors.transparent,),
],
);
listColumns.add(col);
}
return listColumns;
}
String validateNumberInput(input) {
String error = AppLocalizations.of(context).translate(
"Please type the right quantity 0-10000");
dynamic rc = (input != null && input.length > 0);
if (!rc) {
return null;
}
Pattern pattern = r'^\d+(?:\.\d+)?$';
RegExp regex = new RegExp(pattern);
if (!regex.hasMatch(input)) {
return error;
}
rc = double.tryParse(input);
if (rc == null) {
return error;
}
if (!(double.parse(input) < 10000 && double.parse(input) > 0)) {
return error;
}
return null;
}
}
+187
View File
@@ -0,0 +1,187 @@
import 'dart:collection';
import 'package:aitrainer_app/bloc/exercise_by_plan/exercise_by_plan_bloc.dart';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/workout_tree.dart';
import 'package:aitrainer_app/widgets/app_bar_common.dart';
import 'package:aitrainer_app/widgets/splash.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_treeview/tree_view.dart';
class ExerciseByPlanPage extends StatefulWidget {
@override
_ExerciseByPlanPage createState() => _ExerciseByPlanPage();
}
class _ExerciseByPlanPage extends State<ExerciseByPlanPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
// ignore: close_sinks
ExerciseByPlanBloc bloc;
@override
void initState() {
super.initState();
/// We require the initializers to run after the loading screen is rendered
SchedulerBinding.instance.addPostFrameCallback((_) {
BlocProvider.of<ExerciseByPlanBloc>(context).add(ExerciseByPlanLoad());
});
}
@override
Widget build(BuildContext context) {
LinkedHashMap arguments = ModalRoute.of(context).settings.arguments;
final int customerId = arguments['customerId'];
bloc = BlocProvider.of<ExerciseByPlanBloc>(context);
bloc.customerId = customerId;
return Scaffold(
key: _scaffoldKey,
appBar: AppBarCommonNav(),
body: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
image: DecorationImage(
image: customerId == Cache().userLoggedIn.customerId ? AssetImage('asset/image/WT_light_background.png'):
AssetImage('asset/image/WT_menu_dark.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: BlocConsumer<ExerciseByPlanBloc, ExerciseByPlanState>(listener: (context, state) {
if (state is ExerciseByPlanError) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
state.message,
),
backgroundColor: Colors.orange,
));
} else if (state is ExerciseByPlanLoading) {
LoadingDialog();
}
},
// ignore: missing_return
builder: (context, state) {
if (state is ExerciseByPlanStateInitial || state is ExerciseByPlanLoading) {
return Container();
} else if (state is ExerciseByPlanReady) {
return exerciseWidget(bloc);
} else if (state is ExerciseByPlanError) {
return exerciseWidget(bloc);
}
})));
}
Widget exerciseWidget(ExerciseByPlanBloc bloc) {
final LinkedHashMap args = LinkedHashMap();
TreeViewController _treeViewController = TreeViewController(children: nodeExercisePlan(bloc));
TreeViewTheme _treeViewTheme = TreeViewTheme(
expanderTheme: ExpanderThemeData(
type: ExpanderType.plusMinus,
modifier: ExpanderModifier.circleOutlined,
position: ExpanderPosition.start,
color: Colors.black26,
size: 10,
),
labelStyle: TextStyle(fontSize: 14, letterSpacing: 0, color: Colors.blue.shade800),
parentLabelStyle: TextStyle(
fontSize: 14,
letterSpacing: 0.3,
fontWeight: FontWeight.w800,
color: Colors.orange.shade600,
),
iconTheme: IconThemeData(
size: 20,
color: Colors.blue.shade800,
),
colorScheme: bloc.customerId == Cache().userLoggedIn.customerId ? ColorScheme.light(background: Colors.transparent) : ColorScheme.dark(background: Colors.transparent),
);
return Scaffold(
backgroundColor: Colors.transparent,
body: TreeView(
controller: _treeViewController,
allowParentSelect: false,
supportParentDoubleTap: false,
//onExpansionChanged: _expandNodeHandler,
onNodeTap: (key) {
/* Node<dynamic> node = _treeViewController.getNode(key);
WorkoutTree workoutTree = node.data as WorkoutTree;
bloc.exercisePlanRepository.setActualPlanDetail(workoutTree.exerciseType);
print("change node " + node.label + " key " + key);
bloc.add(ExercisePlanUpdate(workoutTree: workoutTree));
Navigator.of(context).pushNamed("exercisePlanDetailAdd", arguments: bloc); */
Node<dynamic> node = _treeViewController.getNode(key);
WorkoutTree workoutTree = node.data as WorkoutTree;
args['blocExerciseByPlan'] = bloc;
args['customerId'] = bloc.customerId;
args['workoutTree'] = workoutTree;
Navigator.of(context).pushNamed("exerciseAddByPlanPage", arguments: args);
},
theme: _treeViewTheme,
),
//bottomNavigationBar: BottomNavigator(bottomNavIndex: 2),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
);
}
List<Node> nodeExercisePlan(ExerciseByPlanBloc bloc) {
List<Node> nodes = List<Node>();
Node actualNode;
bool isEnglish = AppLanguage().appLocal == Locale("en");
bloc.menuTreeRepository.sortedTree.forEach((name, list) {
List<WorkoutTree> listWorkoutItem = list;
List<Node> listExerciseTypePerMuscle = List<Node>();
NodeIcon icon;
listWorkoutItem.forEach((element) {
WorkoutTree treeItem = element;
if ( treeItem.selected ) {
icon =
treeItem.executed == false ? NodeIcon(codePoint: Icons.bubble_chart.codePoint, color: "blueAccent") :
NodeIcon(codePoint: Icons.check_box.codePoint, color: "green");
String exerciseLabel = isEnglish
? treeItem.name
: treeItem.exerciseType == null ? treeItem.name : treeItem.exerciseType.nameTranslation;
List<Node<dynamic>> planDetailList = List<Node<dynamic>>();
String planDetail = bloc.exercisePlanRepository.getPlanDetail(treeItem.exerciseTypeId);
if (planDetail.length > 0) {
exerciseLabel += " (" + planDetail + ")";
}
actualNode = Node(
label: exerciseLabel,
key: treeItem.id.toString(),
data: treeItem,
expanded: planDetailList.length > 0 ? true : false,
children: [],
icon: icon);
listExerciseTypePerMuscle.add(actualNode);
}
});
if (name != null) {
actualNode = Node(
label: name,
key: name,
expanded: true,
children: listExerciseTypePerMuscle,
icon: NodeIcon(codePoint: Icons.perm_identity.codePoint, color: "orange"));
nodes.add(actualNode);
}
});
return nodes;
}
}
+148
View File
@@ -0,0 +1,148 @@
import 'dart:collection';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/localization/app_localization.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/customer_repository.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/widgets/app_bar_common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_treeview/tree_view.dart';
class ExerciseLogPage extends StatefulWidget {
@override
_ExerciseLogPage createState() => _ExerciseLogPage();
}
class _ExerciseLogPage extends State<ExerciseLogPage> {
@override
Widget build(BuildContext context) {
LinkedHashMap arguments = ModalRoute.of(context).settings.arguments;
final ExerciseRepository exerciseRepository = arguments['exerciseRepository'];
final CustomerRepository customerRepository = arguments['customerRepository'];
final int customerId = arguments['customerId'];
return Scaffold(
appBar: AppBarCommonNav(),
body: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
image: DecorationImage(
image: customerId == Cache().userLoggedIn.customerId ? AssetImage('asset/image/WT_light_background.png'):
AssetImage('asset/image/WT_menu_dark.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: exerciseWidget(exerciseRepository, customerId),
)
);
}
Widget exerciseWidget(ExerciseRepository exerciseRepository, int customerId) {
TreeViewController _treeViewController =
TreeViewController(children: nodeExercises(exerciseRepository, customerId));
TreeViewTheme _treeViewTheme = TreeViewTheme(
expanderTheme: ExpanderThemeData(
type: ExpanderType.caret,
modifier: ExpanderModifier.none,
position: ExpanderPosition.start,
color: Colors.red.shade800,
size: 20,
),
labelStyle: TextStyle(
fontSize: 12,
letterSpacing: 0.1,
),
parentLabelStyle: TextStyle(
fontSize: 16,
letterSpacing: 0.1,
fontWeight: FontWeight.w800,
color: Colors.orange.shade600,
),
iconTheme: IconThemeData(
size: 18,
color: Colors.grey.shade800,
),
colorScheme: ColorScheme.light(background: Colors.transparent),
);
return TreeView(
controller: _treeViewController,
allowParentSelect: false,
supportParentDoubleTap: false,
//onExpansionChanged: _expandNodeHandler,
onNodeTap: (key) {
setState(() {
_treeViewController = _treeViewController.copyWith(selectedKey: key);
});
},
theme: _treeViewTheme,
);
}
List<Node> nodeExercises(ExerciseRepository exerciseRepository, int customerId) {
List<Node> nodes = List<Node>();
List<Exercise> exercises;
if ( customerId == Cache().userLoggedIn.customerId ) {
exercises = exerciseRepository.getExerciseList();
} else if ( Cache().getTrainee() != null && customerId == Cache().getTrainee().customerId ) {
exercises = exerciseRepository.getExerciseListTrainee();
}
String prevDay = "";
Node actualNode;
List<Node> listExercisesPerDay;
exercises.forEach((element) {
Exercise exercise = element;
ExerciseType exerciseType =
exerciseRepository.getExerciseTypeById(exercise.exerciseTypeId);
String actualDay = exercise.dateAdd.year.toString() +
"-" +
exercise.dateAdd.month.toString() +
"-" +
exercise.dateAdd.day.toString();
if (prevDay.compareTo(actualDay) != 0) {
listExercisesPerDay = List<Node>();
actualNode = Node(
label: actualDay,
key: exercise.dateAdd.toString(),
expanded: true,
children: listExercisesPerDay,
icon:
NodeIcon(codePoint: Icons.date_range.codePoint, color: "blue"));
nodes.add(actualNode);
prevDay = actualDay;
}
String exerciseName = AppLanguage().appLocal == Locale("en")
? exerciseType.name
: exerciseType.nameTranslation;
String unitQuantity = exerciseType.unitQuantity == "1"
? exercise.unitQuantity.toStringAsFixed(0) +
" " +
AppLocalizations.of(context)
.translate(exerciseType.unitQuantityUnit) +
" "
: "";
String labelExercise = exerciseName +
" " +
unitQuantity +
exercise.quantity.toStringAsFixed(0) +
" " +
AppLocalizations.of(context).translate(exercise.unit);
listExercisesPerDay.add(Node(
label: labelExercise,
key: exercise.exerciseId.toString(),
expanded: false,
icon: NodeIcon(codePoint: Icons.repeat.codePoint, color: "blue")));
});
return nodes;
}
}
+190
View File
@@ -0,0 +1,190 @@
import 'dart:collection';
import 'package:aitrainer_app/bloc/exercise_plan/exercise_plan_bloc.dart';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/workout_tree.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/widgets/app_bar_common.dart';
import 'package:aitrainer_app/widgets/splash.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_treeview/tree_view.dart';
class ExercisePlanCustomPage extends StatefulWidget {
@override
_ExercisePlanCustomPage createState() => _ExercisePlanCustomPage();
}
class _ExercisePlanCustomPage extends State<ExercisePlanCustomPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
// ignore: close_sinks
ExercisePlanBloc bloc;
@override
void initState() {
super.initState();
/// We require the initializers to run after the loading screen is rendered
SchedulerBinding.instance.addPostFrameCallback((_) {
BlocProvider.of<ExercisePlanBloc>(context).add(ExercisePlanLoad());
});
}
@override
Widget build(BuildContext context) {
LinkedHashMap arguments = ModalRoute.of(context).settings.arguments;
final ExerciseRepository exerciseRepository = arguments['exerciseRepository'];
final int customerId = arguments['customerId'];
bloc = BlocProvider.of<ExercisePlanBloc>(context);
bloc.customerId = customerId;
return Scaffold(
key: _scaffoldKey,
appBar: AppBarCommonNav(),
body: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
image: DecorationImage(
image: customerId == Cache().userLoggedIn.customerId ? AssetImage('asset/image/WT_light_background.png'):
AssetImage('asset/image/WT_menu_dark.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: BlocConsumer<ExercisePlanBloc, ExercisePlanState>(listener: (context, state) {
if (state is ExercisePlanError) {
//showInSnackBar(state.message);
//return exerciseWidget(bloc);
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
state.message,
),
backgroundColor: Colors.orange,
));
} else if (state is ExercisePlanLoading) {
LoadingDialog();
}
},
// ignore: missing_return
builder: (context, state) {
if (state is ExercisePlanInitial) {
return Container();
} else if (state is ExercisePlanReady) {
return exerciseWidget(bloc);
} else if (state is ExercisePlanError) {
return exerciseWidget(bloc);
} else if (state is ExercisePlanLoading) {
return Container();
}
})));
}
Widget exerciseWidget(ExercisePlanBloc bloc) {
TreeViewController _treeViewController = TreeViewController(children: nodeExercisePlan(bloc));
TreeViewTheme _treeViewTheme = TreeViewTheme(
expanderTheme: ExpanderThemeData(
type: ExpanderType.plusMinus,
modifier: ExpanderModifier.circleOutlined,
position: ExpanderPosition.start,
color: Colors.black26,
size: 10,
),
labelStyle: TextStyle(fontSize: 14, letterSpacing: 0, color: Colors.blue.shade800),
parentLabelStyle: TextStyle(
fontSize: 14,
letterSpacing: 0.3,
fontWeight: FontWeight.w800,
color: Colors.orange.shade600,
),
iconTheme: IconThemeData(
size: 20,
color: Colors.blue.shade800,
),
colorScheme: bloc.customerId == Cache().userLoggedIn.customerId ? ColorScheme.light(background: Colors.transparent) : ColorScheme.dark(background: Colors.transparent),
);
return Scaffold(
backgroundColor: Colors.transparent,
body: TreeView(
controller: _treeViewController,
allowParentSelect: true,
supportParentDoubleTap: false,
//onExpansionChanged: _expandNodeHandler,
onNodeTap: (key) {
Node<dynamic> node = _treeViewController.getNode(key);
WorkoutTree workoutTree = node.data as WorkoutTree;
bloc.exercisePlanRepository.setActualPlanDetail(workoutTree.exerciseType);
print("change node " + node.label + " key " + key);
bloc.add(ExercisePlanUpdate(workoutTree: workoutTree));
Navigator.of(context).pushNamed("exercisePlanDetailAdd", arguments: bloc);
},
theme: _treeViewTheme,
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.blueAccent,
child: Icon(Icons.save_alt),
onPressed: () => {
bloc.add(ExercisePlanSave()),
if (bloc.exercisePlanRepository.getExercisePlanDetailSize() > 0) {
Navigator.of(context).pop()
}
}
),
//bottomNavigationBar: BottomNavigator(bottomNavIndex: 2),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
);
}
List<Node> nodeExercisePlan(ExercisePlanBloc bloc) {
List<Node> nodes = List<Node>();
Node actualNode;
bool isEnglish = AppLanguage().appLocal == Locale("en");
bloc.menuTreeRepository.sortedTree.forEach((name, list) {
List<WorkoutTree> listWorkoutItem = list;
List<Node> listExerciseTypePerMuscle = List<Node>();
NodeIcon icon;
listWorkoutItem.forEach((element) {
WorkoutTree treeItem = element;
icon =
treeItem.selected == true ? NodeIcon(codePoint: Icons.bubble_chart.codePoint, color: "blueAccent") : null;
String exerciseLabel = isEnglish
? treeItem.name
: treeItem.exerciseType == null ? treeItem.name : treeItem.exerciseType.nameTranslation;
List<Node<dynamic>> planDetailList = List<Node<dynamic>>();
String planDetail = bloc.exercisePlanRepository.getPlanDetail(treeItem.exerciseTypeId);
if (planDetail.length > 0) {
exerciseLabel += " (" + planDetail +")";
}
actualNode = Node(
label: exerciseLabel,
key: treeItem.id.toString(),
data: treeItem,
expanded: planDetailList.length > 0 ? true : false,
children: [],
icon: icon);
listExerciseTypePerMuscle.add(actualNode);
});
//print ("Node name " + name);
if (name != null) {
actualNode = Node(
label: name, // AppLocalizations.of(context).translate(name),
key: name,
expanded: true,
children: listExerciseTypePerMuscle,
icon: NodeIcon(codePoint: Icons.perm_identity.codePoint, color: "orange"));
nodes.add(actualNode);
}
});
return nodes;
}
}
+144
View File
@@ -0,0 +1,144 @@
import 'package:aitrainer_app/bloc/exercise_plan/exercise_plan_bloc.dart';
import 'package:aitrainer_app/bloc/exercise_plan_custom_form.dart';
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
import 'package:aitrainer_app/widgets/app_bar_common.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
class ExercisePlanDetailAddPage extends StatefulWidget {
@override
_ExercisePlanDetailAddPage createState() => _ExercisePlanDetailAddPage();
}
class _ExercisePlanDetailAddPage extends State<ExercisePlanDetailAddPage> {
@override
Widget build(BuildContext context) {
// ignore: close_sinks
final ExercisePlanBloc planBloc = ModalRoute.of(context).settings.arguments;
final ExercisePlanRepository exercisePlanRepository = planBloc.exercisePlanRepository;
return BlocProvider(
create: (context) => ExercisePlanCustomerFormBloc(exercisePlanRepository: exercisePlanRepository, planBloc: planBloc),
child: Builder(builder: (context) {
// ignore: close_sinks
final bloc = BlocProvider.of<ExercisePlanCustomerFormBloc>(context);
String exerciseName = "";
if (bloc != null) {
exerciseName = AppLanguage().appLocal == Locale("en")
? bloc.exercisePlanRepository.actualPlanDetail.exerciseType.name
: bloc.exercisePlanRepository.actualPlanDetail.exerciseType.nameTranslation;
}
return Form(
autovalidate: true,
child: Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBarCommonNav(),
body: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.png'),
fit: BoxFit.fill,
alignment: Alignment.center,
),
),
child: Container(
padding: const EdgeInsets.only(top: 25, left: 25, right: 25),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[
Text(AppLocalizations.of(context).translate('Save The Exercise To The Exercise Plan'),
style: TextStyle(fontSize: 14, color: Colors.blueAccent)),
Text(
exerciseName,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.deepOrange),
overflow: TextOverflow.fade,
maxLines: 1,
softWrap: true,
),
TextFieldBlocBuilder(
textFieldBloc: bloc.serieField,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 30, color: Colors.lightBlue, fontWeight: FontWeight.bold),
inputFormatters: [WhitelistingTextInputFormatter(RegExp(r"[\d.]"))],
decoration: InputDecoration(
fillColor: Colors.white,
filled: false,
hintStyle: TextStyle(fontSize: 16, color: Colors.black54, fontWeight: FontWeight.w100),
hintText: AppLocalizations.of(context).translate("The number of the serie done with"),
labelStyle: TextStyle(fontSize: 16, color: Colors.lightBlue),
labelText: AppLocalizations.of(context).translate("Serie"),
),
),
TextFieldBlocBuilder(
textFieldBloc: bloc.quantityField,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 30, color: Colors.lightBlue, fontWeight: FontWeight.bold),
inputFormatters: [WhitelistingTextInputFormatter(RegExp(r"[\d.]"))],
decoration: InputDecoration(
fillColor: Colors.white,
filled: false,
hintStyle: TextStyle(fontSize: 16, color: Colors.black54, fontWeight: FontWeight.w100),
hintText: AppLocalizations.of(context).translate("The number of the repeats of one serie"),
labelStyle: TextStyle(fontSize: 16, color: Colors.lightBlue),
labelText: AppLocalizations.of(context).translate("Repeats"),
),
),
TextFieldBlocBuilder(
textFieldBloc: bloc.weightField,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 30, color: Colors.lightBlue, fontWeight: FontWeight.bold),
inputFormatters: [WhitelistingTextInputFormatter(RegExp(r"[\d.]"))],
decoration: InputDecoration(
fillColor: Colors.white,
filled: false,
hintStyle: TextStyle(fontSize: 16, color: Colors.black54, fontWeight: FontWeight.w100),
hintText: AppLocalizations.of(context).translate("The weight"),
labelStyle: TextStyle(fontSize: 16, color: Colors.lightBlue),
labelText: AppLocalizations.of(context).translate("Weight"),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
RaisedButton(
textColor: Colors.white,
color: Colors.red.shade300,
focusColor: Colors.white,
onPressed: () => {
print("Remove " + bloc.exercisePlanRepository.actualPlanDetail.exerciseType.name),
planBloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: bloc.exercisePlanRepository.actualPlanDetail)),
Navigator.of(context).pop(),
},
child: Text("Delete"), //Text(AppLocalizations.of(context).translate("Delete"), style: TextStyle(fontSize: 16),)
),
RaisedButton(
textColor: Colors.white,
color: Colors.blueAccent,
focusColor: Colors.white,
onPressed: () => {
bloc.submit(),
Navigator.of(context).pop(),
},
child: Text(
AppLocalizations.of(context).translate("Save"),
style: TextStyle(fontSize: 16),
)),
],
),
]),
))),
),
);
}));
}
}
-147
View File
@@ -1,147 +0,0 @@
import 'package:aitrainer_app/localization/app_language.dart';
import 'package:aitrainer_app/localization/app_localization.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/widgets/app_bar.dart';
import 'package:aitrainer_app/widgets/bottom_nav.dart';
import 'package:flutter/material.dart';
import 'package:flutter_treeview/tree_view.dart';
class MyDevelopmentPage extends StatefulWidget {
@override
_MyDevelopmentPage createState() => _MyDevelopmentPage();
}
class _MyDevelopmentPage extends State<MyDevelopmentPage> {
@override
Widget build(BuildContext context) {
final ExerciseRepository exerciseRepository = ExerciseRepository();
return Scaffold(
appBar: AppBarNav(),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: Container(
padding: EdgeInsets.all(10),
child:
exerciseWidget(exerciseRepository),
)
),
bottomNavigationBar: BottomNavigator(bottomNavIndex: 1));
}
Widget exerciseWidget(ExerciseRepository exerciseRepository) {
TreeViewController _treeViewController = TreeViewController(children: nodeExercises(exerciseRepository) );
TreeViewTheme _treeViewTheme = TreeViewTheme(
expanderTheme: ExpanderThemeData(
type: ExpanderType.caret,
modifier: ExpanderModifier.none,
position: ExpanderPosition.start,
color: Colors.red.shade800,
size: 20,
),
labelStyle: TextStyle(
fontSize: 12,
letterSpacing: 0.1,
),
parentLabelStyle: TextStyle(
fontSize: 16,
letterSpacing: 0.1,
fontWeight: FontWeight.w800,
color: Colors.orange.shade600,
),
iconTheme: IconThemeData(
size: 18,
color: Colors.grey.shade800,
),
colorScheme: ColorScheme.light(
background: Colors.transparent
),
);
return TreeView(
controller: _treeViewController,
allowParentSelect: false,
supportParentDoubleTap: false,
//onExpansionChanged: _expandNodeHandler,
onNodeTap: (key) {
setState(() {
_treeViewController = _treeViewController.copyWith(selectedKey: key);
});
},
theme: _treeViewTheme,
);
}
List<Node> nodeExercises(ExerciseRepository exerciseRepository) {
List<Node> nodes = List<Node>();
List<Exercise> exercises = exerciseRepository.getExerciseList();
String prevDay = "";
Node actualNode;
List<Node> listExercisesPerDay;
exercises.forEach((element) {
Exercise exercise = element;
ExerciseType exerciseType =
exerciseRepository.getExerciseTypeById(exercise.exerciseTypeId);
String actualDay = exercise.dateAdd.year.toString()+"-"+
exercise.dateAdd.month.toString()+"-"+
exercise.dateAdd.day.toString();
if ( prevDay.compareTo(actualDay) != 0) {
listExercisesPerDay = List<Node>();
actualNode =
Node(
label: actualDay,
key: exercise.dateAdd.toString(),
expanded: true,
children: listExercisesPerDay,
icon: NodeIcon(
codePoint: Icons.date_range.codePoint,
color: "blue"
)
);
nodes.add(actualNode);
prevDay = actualDay;
}
String exerciseName = AppLanguage().appLocal == Locale("en") ?
exerciseType.name :
exerciseType.nameTranslation;
String unitQuantity = exerciseType.unitQuantity == "1" ?
exercise.unitQuantity.toStringAsFixed(0)
+ " " + AppLocalizations.of(context).translate(exerciseType.unitQuantityUnit) + " "
: "";
String labelExercise =
exerciseName + " " + unitQuantity
+ exercise.quantity.toStringAsFixed(0) + " "
+ AppLocalizations.of(context).translate(exercise.unit);
listExercisesPerDay.add(
Node(
label: labelExercise,
key: exercise.exerciseId.toString(),
expanded: false,
icon: NodeIcon(
codePoint: Icons.repeat.codePoint,
color: "blue"
)
)
);
});
return nodes;
}
}
+196
View File
@@ -0,0 +1,196 @@
import 'dart:collection';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/widgets/app_bar_common.dart';
import 'package:aitrainer_app/widgets/bottom_nav.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class MyExercisePlanPage extends StatefulWidget {
@override
_MyExercisePlanPage createState() => _MyExercisePlanPage();
}
class _MyExercisePlanPage extends State<MyExercisePlanPage> {
@override
Widget build(BuildContext context) {
final ExerciseRepository exerciseRepository = ExerciseRepository();
final LinkedHashMap args = LinkedHashMap();
return Scaffold(
appBar: AppBarCommonNav(),
body: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
child: CustomScrollView(
scrollDirection: Axis.vertical,
slivers:
[
SliverGrid(
delegate: SliverChildListDelegate(
[
FlatButton(
padding: EdgeInsets.all(10),
textColor: Colors.white,
color: Colors.black12,
focusColor: Colors.blueAccent,
onPressed: () =>
{
args['customerId'] = Cache().userLoggedIn.customerId,
Navigator.of(context).pushNamed('exerciseByPlanPage',
arguments: args)
},
child: Text("Execute My Selected Training Plan",
style: TextStyle(fontSize: 18),)
),
FlatButton(
padding: EdgeInsets.all(0),
textColor: Colors.white,
color: Colors.black12,
focusColor: Colors.blueAccent,
onPressed: () =>
{
args['exerciseRepository'] = exerciseRepository,
args['customerId'] = Cache().userLoggedIn.customerId,
Navigator.of(context).pushNamed('exercisePlanCustomPage',
arguments: args)
},
child: Text("Edit My Custom Plan",
style: TextStyle(fontSize: 18),)
),
FlatButton(
padding: EdgeInsets.all(20),
textColor: Colors.white,
color: Colors.black12,
focusColor: Colors.blueAccent,
onPressed: () =>
{
},
child: Text("Suggested Plan",
style: TextStyle(fontSize: 18),)
),
Stack(
fit: StackFit.passthrough,
overflow: Overflow.clip,
alignment: Alignment.topLeft,
children: [
Image.asset('asset/image/lock.png',
height: 40,
width: 40,
),
FlatButton(
padding: EdgeInsets.all(20),
textColor: Colors.white,
color: Colors.black12,
focusColor: Colors.blueAccent,
onPressed: () =>
{
},
child: Text("My Special Plan",
style: TextStyle(fontSize: 18),)
),
],
),
Stack(
fit: StackFit.passthrough,
overflow: Overflow.clip,
children: [
Image.asset('asset/image/lock.png',
height: 40,
width: 40,
),
FlatButton(
padding: EdgeInsets.all(20),
textColor: Colors.white,
color: Colors.black12,
focusColor: Colors.blueAccent,
onPressed: () =>
{
},
child: Text("My Arnold's Plan",
style: TextStyle(fontSize: 18),)
),
]
),
hiddenPlanWidget(exerciseRepository),
hiddenTrainingWidget(),
]
),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 20.0,
crossAxisSpacing: 20.0,
childAspectRatio: 1.2,
),
)
]
)
),
bottomNavigationBar: BottomNavigator(bottomNavIndex: 2));
}
Widget hiddenPlanWidget(ExerciseRepository exerciseRepository) {
final LinkedHashMap args = LinkedHashMap();
if ( Cache().getTrainee() != null ) {
return FlatButton(
padding: EdgeInsets.all(20),
textColor: Colors.white,
color: Colors.black12,
focusColor: Colors.blueAccent,
onPressed: () =>
{
args['exerciseRepository'] = exerciseRepository,
args['customerId'] = Cache().getTrainee().customerId,
Navigator.of(context).pushNamed('exercisePlanCustomPage',
arguments: args)
},
child: Text("My Trainee's Plan",
style: TextStyle(fontSize: 18),)
);
} else {
return Container();
}
}
Widget hiddenTrainingWidget() {
final LinkedHashMap args = LinkedHashMap();
if ( Cache().getTrainee() != null ) {
print ("!!Trainee: " + Cache().getTrainee().firstname + " " + Cache().getTrainee().name);
return FlatButton(
padding: EdgeInsets.all(20),
textColor: Colors.white,
color: Colors.black12,
focusColor: Colors.blueAccent,
onPressed: () =>
{
args['customerId'] = Cache().getTrainee().customerId,
Navigator.of(context).pushNamed('exerciseByPlanPage',
arguments: args)
},
child: Text("Execute My Trainee's Training Plan",
style: TextStyle(fontSize: 18),)
);
} else {
return Container();
}
}
}
+7
View File
@@ -109,6 +109,13 @@ class SettingsPage extends StatelessWidget{
)
),
ListTile(
leading: Icon(Icons.get_app),
title: RaisedButton(
child: Text("Check lang", style: TextStyle(fontSize: 12),),
onPressed: () => settingsBloc.add(SettingsGetLanguage()),
)
)
]
);
}