mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-04 20:52:26 +01:00
Further work on rendering the new routines
This commit is contained in:
@@ -34,7 +34,7 @@ class DayData {
|
||||
late String? label;
|
||||
|
||||
@JsonKey(required: false)
|
||||
late Day day;
|
||||
late Day? day;
|
||||
|
||||
@JsonKey(required: false)
|
||||
late List<SlotData> slots;
|
||||
|
||||
@@ -15,7 +15,7 @@ DayData _$DayDataFromJson(Map<String, dynamic> json) {
|
||||
iteration: (json['iteration'] as num).toInt(),
|
||||
date: DateTime.parse(json['date'] as String),
|
||||
label: json['label'] as String?,
|
||||
day: Day.fromJson(json['day'] as Map<String, dynamic>),
|
||||
day: json['day'] == null ? null : Day.fromJson(json['day'] as Map<String, dynamic>),
|
||||
slots: (json['slots'] as List<dynamic>)
|
||||
.map((e) => SlotData.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
|
||||
@@ -56,6 +56,9 @@ class Routine {
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
List<DayData> dayDataCurrentIteration = [];
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
List<DayData> dayDataCurrentIterationGym = [];
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
List<Log> logs = [];
|
||||
|
||||
|
||||
@@ -38,6 +38,9 @@ class SetConfigData {
|
||||
@JsonKey(required: true)
|
||||
late String type;
|
||||
|
||||
@JsonKey(required: true, name: 'text_repr')
|
||||
late String textRepr;
|
||||
|
||||
@JsonKey(required: true, name: 'sets')
|
||||
late num? nrOfSets;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ SetConfigData _$SetConfigDataFromJson(Map<String, dynamic> json) {
|
||||
'exercise',
|
||||
'slot_entry_id',
|
||||
'type',
|
||||
'text_repr',
|
||||
'sets',
|
||||
'weight',
|
||||
'max_weight',
|
||||
@@ -46,6 +47,7 @@ SetConfigData _$SetConfigDataFromJson(Map<String, dynamic> json) {
|
||||
maxRestTime: stringToNum(json['max_rest'] as String?),
|
||||
comment: json['comment'] as String,
|
||||
)
|
||||
..textRepr = json['text_repr'] as String
|
||||
..nrOfSets = json['sets'] as num?
|
||||
..maxWeight = stringToNumNull(json['max_weight'] as String?);
|
||||
}
|
||||
@@ -54,6 +56,7 @@ Map<String, dynamic> _$SetConfigDataToJson(SetConfigData instance) => <String, d
|
||||
'exercise': instance.exerciseId,
|
||||
'slot_entry_id': instance.slotEntryId,
|
||||
'type': instance.type,
|
||||
'text_repr': instance.textRepr,
|
||||
'sets': instance.nrOfSets,
|
||||
'weight': instance.weight,
|
||||
'max_weight': instance.maxWeight,
|
||||
|
||||
@@ -41,7 +41,8 @@ class RoutinesProvider with ChangeNotifier {
|
||||
static const _routinesUrlPath = 'routine';
|
||||
static const _routinesStructureSubpath = 'structure';
|
||||
static const _routinesDateSequenceSubpath = 'date-sequence-display';
|
||||
static const _routinesCurrentIterationSubpath = 'current-iteration-display';
|
||||
static const _routinesCurrentIterationDisplaySubpath = 'current-iteration-display';
|
||||
static const _routinesCurrentIterationGymSubpath = 'current-iteration-gym';
|
||||
static const _daysUrlPath = 'day';
|
||||
static const _slotsUrlPath = 'slot';
|
||||
static const _slotEntriesUrlPath = 'slot-entry';
|
||||
@@ -220,15 +221,28 @@ class RoutinesProvider with ChangeNotifier {
|
||||
baseProvider.makeUrl(
|
||||
_routinesUrlPath,
|
||||
id: routineId,
|
||||
objectMethod: _routinesCurrentIterationSubpath,
|
||||
objectMethod: _routinesCurrentIterationDisplaySubpath,
|
||||
),
|
||||
)
|
||||
),
|
||||
baseProvider.fetch(
|
||||
baseProvider.makeUrl(
|
||||
_routinesUrlPath,
|
||||
id: routineId,
|
||||
objectMethod: _routinesCurrentIterationGymSubpath,
|
||||
),
|
||||
),
|
||||
baseProvider.fetchPaginated(baseProvider.makeUrl(
|
||||
_logsUrlPath,
|
||||
query: {'workout': routineId.toString(), 'limit': '900'},
|
||||
))
|
||||
]);
|
||||
|
||||
final routine = Routine.fromJson(results[0] as Map<String, dynamic>);
|
||||
|
||||
final dayData = results[1] as List<dynamic>;
|
||||
final currentIterationData = results[2] as List<dynamic>;
|
||||
final currentIterationDisplayData = results[2] as List<dynamic>;
|
||||
final currentIterationGymData = results[2] as List<dynamic>;
|
||||
final logData = results[3] as List<dynamic>;
|
||||
|
||||
/*
|
||||
* Set exercise, repetition and weight unit objects
|
||||
@@ -237,9 +251,13 @@ class RoutinesProvider with ChangeNotifier {
|
||||
setExercisesAndUnits(dayDataEntries); // in-place update
|
||||
|
||||
final currentIterationDayDataEntries =
|
||||
currentIterationData.map((entry) => DayData.fromJson(entry)).toList();
|
||||
currentIterationDisplayData.map((entry) => DayData.fromJson(entry)).toList();
|
||||
setExercisesAndUnits(currentIterationDayDataEntries); // in-place update
|
||||
|
||||
// final currentIterationDayDataEntriesGym =
|
||||
// currentIterationGymData.map((entry) => DayData.fromJson(entry)).toList();
|
||||
// setExercisesAndUnits(currentIterationDayDataEntriesGym); // in-place update
|
||||
|
||||
for (final day in routine.days) {
|
||||
for (final slot in day.slots) {
|
||||
for (final slotEntry in slot.entries) {
|
||||
@@ -256,14 +274,15 @@ class RoutinesProvider with ChangeNotifier {
|
||||
|
||||
routine.dayData = dayDataEntries;
|
||||
routine.dayDataCurrentIteration = currentIterationDayDataEntries;
|
||||
// routine.dayDataCurrentIterationGym = currentIterationDayDataEntriesGym;
|
||||
|
||||
// Logs
|
||||
routine.logs = [];
|
||||
|
||||
final logData = await baseProvider.fetchPaginated(baseProvider.makeUrl(
|
||||
_logsUrlPath,
|
||||
query: {'workout': routineId.toString(), 'limit': '100'},
|
||||
));
|
||||
// final logData = await baseProvider.fetchPaginated(baseProvider.makeUrl(
|
||||
// _logsUrlPath,
|
||||
// query: {'workout': routineId.toString(), 'limit': '900'},
|
||||
// ));
|
||||
for (final logEntry in logData) {
|
||||
try {
|
||||
final log = Log.fromJson(logEntry);
|
||||
|
||||
@@ -387,59 +387,61 @@ class _DashboardWorkoutWidgetState extends State<DashboardWorkoutWidget> {
|
||||
return out;
|
||||
}
|
||||
|
||||
for (final day in _workoutPlan!.days) {
|
||||
for (final dayData in _workoutPlan!.dayDataCurrentIteration) {
|
||||
out.add(SizedBox(
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
day.name,
|
||||
dayData.day == null || dayData.day!.isRest ? 'REST DAY' : dayData.day!.name,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: MutedText(day.description, textAlign: TextAlign.right),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.play_arrow),
|
||||
color: wgerPrimaryButtonColor,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: day);
|
||||
},
|
||||
child: MutedText(dayData.day != null ? dayData.day!.description : '',
|
||||
textAlign: TextAlign.right),
|
||||
),
|
||||
if (dayData.day == null || dayData.day!.isRest)
|
||||
const Icon(Icons.hotel)
|
||||
else
|
||||
IconButton(
|
||||
icon: const Icon(Icons.play_arrow),
|
||||
color: wgerPrimaryButtonColor,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(GymModeScreen.routeName, arguments: dayData);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
for (final set in day.slots) {
|
||||
for (final slotData in dayData.slots) {
|
||||
out.add(SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...set.settingsFiltered.map((s) {
|
||||
return _showDetail
|
||||
...slotData.setConfigs.map(
|
||||
(s) => _showDetail
|
||||
? Column(
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(s.exerciseObj
|
||||
Text(s.exercise
|
||||
.getExercise(Localizations.localeOf(context).languageCode)
|
||||
.name),
|
||||
const SizedBox(width: 10),
|
||||
MutedText(
|
||||
set.getSmartRepr(s.exerciseObj).join('\n'),
|
||||
),
|
||||
MutedText(s.textRepr),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
)
|
||||
: Container();
|
||||
}),
|
||||
: Container(),
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
@@ -21,9 +21,8 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/models/workouts/day_data.dart';
|
||||
import 'package:wger/models/workouts/slot.dart';
|
||||
import 'package:wger/models/workouts/set_config_data.dart';
|
||||
import 'package:wger/models/workouts/slot_data.dart';
|
||||
import 'package:wger/models/workouts/slot_entry.dart';
|
||||
import 'package:wger/providers/workout_plans.dart';
|
||||
import 'package:wger/screens/form_screen.dart';
|
||||
import 'package:wger/screens/gym_mode.dart';
|
||||
@@ -33,14 +32,12 @@ import 'package:wger/widgets/exercises/images.dart';
|
||||
import 'package:wger/widgets/workouts/forms.dart';
|
||||
|
||||
class SettingWidget extends StatelessWidget {
|
||||
final Slot set;
|
||||
final SlotEntry setting;
|
||||
final SetConfigData setConfigData;
|
||||
final bool expanded;
|
||||
final Function toggle;
|
||||
|
||||
const SettingWidget({
|
||||
required this.set,
|
||||
required this.setting,
|
||||
required this.setConfigData,
|
||||
required this.expanded,
|
||||
required this.toggle,
|
||||
});
|
||||
@@ -48,45 +45,39 @@ class SettingWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: InkWell(
|
||||
child: SizedBox(
|
||||
width: 45,
|
||||
child: ExerciseImageWidget(image: setting.exerciseObj.getMainImage),
|
||||
),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(setting.exerciseObj
|
||||
.getExercise(Localizations.localeOf(context).languageCode)
|
||||
.name),
|
||||
content: ExerciseDetail(setting.exerciseObj),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
MaterialLocalizations.of(context).closeButtonLabel,
|
||||
leading: InkWell(
|
||||
child: SizedBox(
|
||||
width: 45,
|
||||
child: ExerciseImageWidget(image: setConfigData.exercise.getMainImage),
|
||||
),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(setConfigData.exercise
|
||||
.getExercise(Localizations.localeOf(context).languageCode)
|
||||
.name),
|
||||
content: ExerciseDetail(setConfigData.exercise),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
MaterialLocalizations.of(context).closeButtonLabel,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
title: Text(
|
||||
setting.exerciseObj.getExercise(Localizations.localeOf(context).languageCode).name,
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...set.getSmartRepr(setting.exerciseObj).map((e) => Text(e)),
|
||||
],
|
||||
),
|
||||
);
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
title: Text(
|
||||
setConfigData.exercise.getExercise(Localizations.localeOf(context).languageCode).name,
|
||||
),
|
||||
subtitle: Text(setConfigData.textRepr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +107,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget getSetRow(SlotData slotData, int index) {
|
||||
Widget getSlotDataRow(SlotData slotData, int index) {
|
||||
return Row(
|
||||
key: ValueKey(index),
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
@@ -135,15 +126,13 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
child: Column(
|
||||
children: [
|
||||
if (slotData.comment != '') MutedText(slotData.comment),
|
||||
Text('AAAAAAAA'),
|
||||
// ...set.settingsFiltered.map(
|
||||
// (setting) => SettingWidget(
|
||||
// set: set,
|
||||
// setting: setting,
|
||||
// expanded: _editing,
|
||||
// toggle: _toggleExpanded,
|
||||
// ),
|
||||
// ),
|
||||
...slotData.setConfigs.map(
|
||||
(setting) => SettingWidget(
|
||||
setConfigData: setting,
|
||||
expanded: _editing,
|
||||
toggle: _toggleExpanded,
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
],
|
||||
),
|
||||
@@ -189,7 +178,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
FormScreen.routeName,
|
||||
arguments: FormScreenArguments(
|
||||
AppLocalizations.of(context).newSet,
|
||||
SetFormWidget(widget._dayData.day),
|
||||
SetFormWidget(widget._dayData.day!),
|
||||
hasListView: true,
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
@@ -209,7 +198,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
Provider.of<RoutinesProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).findById(widget._dayData.day.routineId),
|
||||
).findById(widget._dayData.day!.routineId),
|
||||
widget._dayData.day,
|
||||
),
|
||||
hasListView: true,
|
||||
@@ -224,7 +213,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
Provider.of<RoutinesProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).deleteDay(widget._dayData.day);
|
||||
).deleteDay(widget._dayData.day!);
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -253,7 +242,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
},
|
||||
children: [
|
||||
for (var i = 0; i < widget._dayData.slots.length; i++)
|
||||
getSetRow(widget._dayData.slots[i], i),
|
||||
getSlotDataRow(widget._dayData.slots[i], i),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -278,7 +267,7 @@ class DayHeader extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _dayData.day.isRest
|
||||
return _dayData.day == null || _dayData.day!.isRest
|
||||
? ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
title: Text(
|
||||
@@ -292,11 +281,11 @@ class DayHeader extends StatelessWidget {
|
||||
: ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
title: Text(
|
||||
_dayData.day.name,
|
||||
_dayData.day!.name,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Text(_dayData.day.description),
|
||||
subtitle: Text(_dayData.day!.description),
|
||||
leading: const Icon(Icons.play_arrow),
|
||||
minLeadingWidth: 8,
|
||||
trailing: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
|
||||
@@ -73,7 +73,7 @@ class _GymModeState extends State<GymMode> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Calculate amount of elements for progress indicator
|
||||
for (final set in widget._DayData.day.slots) {
|
||||
for (final set in widget._DayData.day!.slots) {
|
||||
_totalElements = _totalElements + set.settingsComputed.length;
|
||||
}
|
||||
// Calculate the pages for the navigation
|
||||
@@ -81,7 +81,7 @@ class _GymModeState extends State<GymMode> {
|
||||
// This duplicates the code below in the getContent method, but it seems to
|
||||
// be the easiest way
|
||||
var currentPage = 1;
|
||||
for (final set in widget._DayData.slots) {
|
||||
for (final _ in widget._DayData.slots) {
|
||||
var firstPage = true;
|
||||
for (final setting in []) {
|
||||
// for (final setting in set.settingsComputed) {
|
||||
@@ -110,7 +110,7 @@ class _GymModeState extends State<GymMode> {
|
||||
var currentElement = 1;
|
||||
final List<Widget> out = [];
|
||||
|
||||
for (final set in widget._DayData.day.slots) {
|
||||
for (final set in widget._DayData.day!.slots) {
|
||||
var firstPage = true;
|
||||
for (final setting in []) {
|
||||
// for (final setting in set.settingsComputed) {
|
||||
@@ -132,7 +132,7 @@ class _GymModeState extends State<GymMode> {
|
||||
setting,
|
||||
set,
|
||||
exerciseBase,
|
||||
workoutProvider.findById(widget._DayData.day.routineId),
|
||||
workoutProvider.findById(widget._DayData.day!.routineId),
|
||||
ratioCompleted,
|
||||
_exercisePages,
|
||||
));
|
||||
@@ -149,11 +149,11 @@ class _GymModeState extends State<GymMode> {
|
||||
return PageView(
|
||||
controller: _controller,
|
||||
children: [
|
||||
StartPage(_controller, widget._DayData.day, _exercisePages),
|
||||
StartPage(_controller, widget._DayData.day!, _exercisePages),
|
||||
...getContent(),
|
||||
SessionPage(
|
||||
Provider.of<RoutinesProvider>(context, listen: false)
|
||||
.findById(widget._DayData.day.routineId),
|
||||
.findById(widget._DayData.day!.routineId),
|
||||
_controller,
|
||||
widget._start,
|
||||
_exercisePages,
|
||||
|
||||
Reference in New Issue
Block a user