181 lines
6.0 KiB
Dart
181 lines
6.0 KiB
Dart
import 'dart:collection';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:aitrainer_app/localization/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/treeview/tree_view.dart';
|
|
import 'package:aitrainer_app/util/common.dart';
|
|
import 'package:aitrainer_app/util/trans.dart';
|
|
import 'package:aitrainer_app/widgets/app_bar_common.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:aitrainer_app/widgets/treeview_parent_widget.dart';
|
|
|
|
class ExerciseLogPage extends StatefulWidget {
|
|
@override
|
|
_ExerciseLogPage createState() => _ExerciseLogPage();
|
|
}
|
|
|
|
class _ExerciseLogPage extends State<ExerciseLogPage> with Trans, Common {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
LinkedHashMap arguments = ModalRoute.of(context).settings.arguments;
|
|
final ExerciseRepository exerciseRepository = arguments['exerciseRepository'];
|
|
final int customerId = arguments['customerId'];
|
|
setContext(context);
|
|
|
|
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) {
|
|
return TreeView(
|
|
startExpanded: false,
|
|
children: _getTreeChildren(exerciseRepository, customerId),
|
|
);
|
|
}
|
|
|
|
List<Widget> _getTreeChildren(ExerciseRepository exerciseRepository, int customerId) {
|
|
if ( customerId == Cache().userLoggedIn.customerId ) {
|
|
exerciseRepository.exerciseList = exerciseRepository.getExerciseList();
|
|
} else if ( Cache().getTrainee() != null && customerId == Cache().getTrainee().customerId ) {
|
|
exerciseRepository.exerciseList = exerciseRepository.getExerciseListTrainee();
|
|
}
|
|
exerciseRepository.sortByDate();
|
|
|
|
List<Widget> listWidget = List();
|
|
|
|
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 = List();
|
|
String origDate = "";
|
|
print("start exercises");
|
|
exerciseRepository.exerciseList.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: true,
|
|
parent: TreeviewParentWidget(text: exerciseDate),
|
|
children: _getChildList(listExercises, exerciseRepository),
|
|
)
|
|
)
|
|
);
|
|
listExercises = List();
|
|
}
|
|
}
|
|
origDate = exerciseDate;
|
|
listExercises.add(exercise);
|
|
|
|
});
|
|
|
|
return listWidget;
|
|
}
|
|
|
|
List<Widget> _getChildList(List<Exercise> listExercises, ExerciseRepository exerciseRepository) {
|
|
List<Widget> list = List();
|
|
bool isEnglish = AppLanguage().appLocal == Locale('en');
|
|
|
|
listExercises.forEach((exercise) {
|
|
ExerciseType exerciseType = exerciseRepository.getExerciseTypeById(exercise.exerciseTypeId);
|
|
String exerciseName = isEnglish ? exerciseType.name : exerciseType.nameTranslation;
|
|
|
|
String unitQuantity = exerciseType.unitQuantity == "1"
|
|
? exercise.unitQuantity.toStringAsFixed(0) +
|
|
" " +
|
|
t(exerciseType.unitQuantityUnit) +
|
|
" "
|
|
: "";
|
|
|
|
String labelExercise =
|
|
unitQuantity +
|
|
exercise.quantity.toStringAsFixed(0) +
|
|
" " +
|
|
t(exercise.unit);
|
|
|
|
list.add(
|
|
Card(
|
|
margin: EdgeInsets.only(left: 10, top: 5),
|
|
color: Colors.white54,
|
|
child: Container(
|
|
padding: const EdgeInsets.only(left: 5, top: 0, right: 5, bottom: 0),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Icon(Icons.accessibility, color: Colors.black12),
|
|
SizedBox(width: 20),
|
|
Flexible(
|
|
child:
|
|
Text(
|
|
exerciseName,
|
|
textAlign: TextAlign.start,
|
|
style: TextStyle(fontSize: 12, color: Colors.black),
|
|
),
|
|
),
|
|
SizedBox(width: 20),
|
|
Text(labelExercise , style: TextStyle(fontSize: 9, color: Colors.blueAccent.shade700),) ,
|
|
]),
|
|
)
|
|
),
|
|
);
|
|
|
|
});
|
|
|
|
return list;
|
|
}
|
|
|
|
}
|