wt1.1.2b exercise_log with the new tree_view
This commit is contained in:
+125
-91
@@ -1,21 +1,23 @@
|
||||
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:flutter_treeview/tree_view.dart';
|
||||
import 'package:aitrainer_app/widgets/exercise_type_widget.dart';
|
||||
|
||||
class ExerciseLogPage extends StatefulWidget {
|
||||
@override
|
||||
_ExerciseLogPage createState() => _ExerciseLogPage();
|
||||
}
|
||||
|
||||
class _ExerciseLogPage extends State<ExerciseLogPage> with Trans {
|
||||
class _ExerciseLogPage extends State<ExerciseLogPage> with Trans, Common {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
LinkedHashMap arguments = ModalRoute.of(context).settings.arguments;
|
||||
@@ -41,106 +43,138 @@ class _ExerciseLogPage extends State<ExerciseLogPage> with Trans {
|
||||
}
|
||||
|
||||
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,
|
||||
startExpanded: false,
|
||||
children: _getTreeChildren(exerciseRepository, customerId),
|
||||
);
|
||||
}
|
||||
|
||||
List<Node> nodeExercises(ExerciseRepository exerciseRepository, int customerId) {
|
||||
List<Node> nodes = List<Node>();
|
||||
List<Exercise> exercises;
|
||||
List<Widget> _getTreeChildren(ExerciseRepository exerciseRepository, int customerId) {
|
||||
if ( customerId == Cache().userLoggedIn.customerId ) {
|
||||
exercises = exerciseRepository.getExerciseList();
|
||||
exerciseRepository.exerciseList = exerciseRepository.getExerciseList();
|
||||
} else if ( Cache().getTrainee() != null && customerId == Cache().getTrainee().customerId ) {
|
||||
exercises = exerciseRepository.getExerciseListTrainee();
|
||||
exerciseRepository.exerciseList = exerciseRepository.getExerciseListTrainee();
|
||||
}
|
||||
exerciseRepository.sortByDate();
|
||||
|
||||
List<Widget> listWidget = List();
|
||||
|
||||
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();
|
||||
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),
|
||||
),
|
||||
|
||||
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;
|
||||
],
|
||||
)
|
||||
)
|
||||
);
|
||||
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: ExerciseTypeWidget(exerciseTypeName: exerciseDate),
|
||||
children: _getChildList(listExercises, exerciseRepository),
|
||||
)
|
||||
)
|
||||
);
|
||||
listExercises = List();
|
||||
}
|
||||
}
|
||||
origDate = exerciseDate;
|
||||
listExercises.add(exercise);
|
||||
|
||||
String exerciseName = AppLanguage().appLocal == Locale("en")
|
||||
? exerciseType.name
|
||||
: exerciseType.nameTranslation;
|
||||
String unitQuantity = exerciseType.unitQuantity == "1"
|
||||
? exercise.unitQuantity.toStringAsFixed(0) +
|
||||
" " +
|
||||
t(exerciseType.unitQuantityUnit) +
|
||||
" "
|
||||
: "";
|
||||
|
||||
String labelExercise = exerciseName +
|
||||
" " +
|
||||
unitQuantity +
|
||||
exercise.quantity.toStringAsFixed(0) +
|
||||
" " +
|
||||
t(exercise.unit);
|
||||
listExercisesPerDay.add(Node(
|
||||
label: labelExercise,
|
||||
key: exercise.exerciseId.toString(),
|
||||
expanded: false,
|
||||
icon: NodeIcon(codePoint: Icons.repeat.codePoint, color: "blue")));
|
||||
});
|
||||
return nodes;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user