mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-30 09:42:50 +01:00
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?
This commit is contained in:
@@ -94,6 +94,13 @@ class WorkoutDayWidget extends StatefulWidget {
|
||||
|
||||
class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
bool _expanded = false;
|
||||
late List<Set> _sets;
|
||||
|
||||
void initState() {
|
||||
super.initState();
|
||||
_sets = widget._day.sets;
|
||||
}
|
||||
|
||||
void _toggleExpanded() {
|
||||
setState(() {
|
||||
_expanded = !_expanded;
|
||||
@@ -102,6 +109,7 @@ class _WorkoutDayWidgetState extends State<WorkoutDayWidget> {
|
||||
|
||||
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<WorkoutDayWidget> {
|
||||
],
|
||||
),
|
||||
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: () {
|
||||
|
||||
Reference in New Issue
Block a user