From db04964f2038d22a8449abe74eebf4412147ead5 Mon Sep 17 00:00:00 2001 From: Arun Muralidharan Date: Sun, 27 Jun 2021 23:36:53 +0200 Subject: [PATCH] Reorder Sets Progress PR for Issue #41. Currently you can edit the order (long press to reorder) in the workout plan screen. The order change is only local; it persists only for the current session. However, I have not figured out how to reflect the changed order in the DB using the API. Does Day even store the order of its Sets in the DB? Or is it dynamically populated into the model in the app? --- lib/widgets/workouts/day.dart | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/widgets/workouts/day.dart b/lib/widgets/workouts/day.dart index f8a25a9d5..90dc749c5 100644 --- a/lib/widgets/workouts/day.dart +++ b/lib/widgets/workouts/day.dart @@ -94,6 +94,13 @@ class WorkoutDayWidget extends StatefulWidget { class _WorkoutDayWidgetState extends State { bool _expanded = false; + late List _sets; + + void initState() { + super.initState(); + _sets = widget._day.sets; + } + void _toggleExpanded() { setState(() { _expanded = !_expanded; @@ -102,6 +109,7 @@ class _WorkoutDayWidgetState extends State { Widget getSetRow(Set set) { return Row( + key: ValueKey(set.id), crossAxisAlignment: CrossAxisAlignment.baseline, textBaseline: TextBaseline.alphabetic, children: [ @@ -198,11 +206,23 @@ class _WorkoutDayWidgetState extends State { ], ), Divider(), - ...widget._day.sets - .map( - (set) => getSetRow(set), - ) - .toList(), + ReorderableListView( + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + onReorder: (oldIndex, newIndex) { + setState(() { + if (oldIndex < newIndex) { + newIndex -= 1; + } + final Set _set = _sets.removeAt(oldIndex); + _sets.insert(newIndex, _set); + }); + }, + children: [ + for (final _set in _sets) + getSetRow(_set), + ], + ), OutlinedButton( child: Text(AppLocalizations.of(context).addSet), onPressed: () {