Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"duplicate": "Duplicate",
"durationLeft": "{timeLeft} of {timeTotal} left",
"durationWithTime": "Duration: {formattedTime}",
"editSetName" : "Edit set name",
"editWorkout": "Edit workout",
"enterWorkoutName": "Please enter a name for the workout!",
"exercise": "Exercise",
Expand Down
41 changes: 36 additions & 5 deletions lib/layouts/workout_builder.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:prompt_dialog/prompt_dialog.dart';
import 'package:uuid/uuid.dart';

import '../generated/l10n.dart';
Expand Down Expand Up @@ -56,7 +57,7 @@ class BuilderPageState extends State<BuilderPage> {
var newSet = Set.fromJson(_workout.sets[index].toJson());
newSet.id = const Uuid().v4();
setState(() {
_workout.sets.insert(index, newSet);
_workout.sets.insert(index + 1, newSet);
_dirty = true;
});
}
Expand Down Expand Up @@ -149,6 +150,20 @@ class BuilderPageState extends State<BuilderPage> {
});
}

void _editSetName(int setIndex) async {
var existingName = _workout.sets[setIndex].name ?? "";
var newName = await prompt(
context,
initialValue: existingName,
maxLength: 15);
if (newName != null && newName != existingName) {
setState(() {
_workout.sets[setIndex].name = newName.isEmpty ? null : newName;
_dirty = true;
});
}
}

Widget _buildSetList() => ReorderableListView(
onReorder: (oldIndex, newIndex) {
if (oldIndex < newIndex) {
Expand Down Expand Up @@ -186,9 +201,16 @@ class BuilderPageState extends State<BuilderPage> {
Expanded(
child: ListTile(
title: Text(
set.name ??
S.of(context).setIndex(_workout.sets.indexOf(set) + 1),
style: const TextStyle(
decoration: TextDecoration.underline,
),
),
subtitle: Text(Utils.formatSeconds(set.duration)),
onLongPress: () {
_editSetName(index);
},
),
),
Text(S.of(context).repetitions),
Expand Down Expand Up @@ -232,12 +254,21 @@ class BuilderPageState extends State<BuilderPage> {
Row(
children: [
IconButton(
icon: const Icon(Icons.delete),
tooltip: S.of(context).deleteSet,
icon: Icon(set.hidden ? Icons.visibility : Icons.visibility_off),
onPressed: () {
_deleteSet(index);
setState(() {
set.hidden = !set.hidden;
_dirty = true;
});
},
),
IconButton(
icon: const Icon(Icons.delete),
tooltip: S.of(context).deleteSet,
onPressed: () {
_deleteSet(index);
}
),
IconButton(
icon: const Icon(Icons.copy),
tooltip: S.of(context).duplicate,
Expand All @@ -264,7 +295,7 @@ class BuilderPageState extends State<BuilderPage> {
_workout.sets[setIndex].exercises.insert(newIndex, ex);
});
},
children: set.exercises
children: set.hidden ? [] : set.exercises
.asMap()
.keys
.map(
Expand Down
11 changes: 10 additions & 1 deletion lib/layouts/workout_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class WorkoutPageState extends State<WorkoutPageContent> {
),
),
),

// right side of footer
Expanded(
child: ListTile(
Expand Down Expand Up @@ -198,7 +199,15 @@ class WorkoutPageState extends State<WorkoutPageContent> {
child: Column(
children: [
Text(
'${S.of(context).setIndex(_workout.sets.indexOf(timetable.currentSet) + 1)} - ${Utils.formatSeconds(timetable.remainingSeconds)}',
timetable.currentSet.name ?? S.of(context).setIndex(_workout.sets.indexOf(timetable.currentSet) + 1),
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
),
),
Text(
Utils.formatSeconds(timetable.remainingSeconds),
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 48,
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/workout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Set {
String? id,
this.repetitions = 1,
List<Exercise>? exercises,
this.name,
this.hidden = false,
}) {
this.id = id ?? const Uuid().v4();
this.exercises = exercises ?? [Exercise()];
Expand All @@ -59,12 +61,17 @@ class Set {
@JsonKey(required: true)
int repetitions;

@JsonKey()
late String? name;

@JsonKey()
late String id;

@JsonKey(required: true)
late List<Exercise> exercises;

bool hidden;

int get duration {
var duration = 0;

Expand Down
2 changes: 2 additions & 0 deletions lib/workout.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
path_provider: '^2.1.3'
pref: '^2.8.0'
prefs: '^4.1.0+3'
prompt_dialog: '^1.0.16'
provider: '^6.1.2'
scrollable_positioned_list: '^0.3.8'
share_plus: '^9.0.0'
Expand Down
Loading