Make whole plan edit scrollable
This commit is contained in:
parent
a383ebfe34
commit
4a83465d82
|
@ -1,63 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class Days extends StatefulWidget {
|
|
||||||
final ValueChanged<String> onChanged;
|
|
||||||
final String days;
|
|
||||||
|
|
||||||
const Days({required this.onChanged, required this.days, super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
createState() => _DaysState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DaysState extends State<Days> {
|
|
||||||
final List<String> _days = [
|
|
||||||
'Monday',
|
|
||||||
'Tuesday',
|
|
||||||
'Wednesday',
|
|
||||||
'Thursday',
|
|
||||||
'Friday',
|
|
||||||
'Saturday',
|
|
||||||
'Sunday'
|
|
||||||
];
|
|
||||||
late List<bool> _selections;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
final dayList = widget.days.split(',');
|
|
||||||
_selections = _days.map((day) => dayList.contains(day)).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
String _getSelectedDaysString() {
|
|
||||||
List<String> selectedDays = [];
|
|
||||||
for (int i = 0; i < _selections.length; i++)
|
|
||||||
if (_selections[i]) selectedDays.add(_days[i]);
|
|
||||||
return selectedDays.join(",");
|
|
||||||
}
|
|
||||||
|
|
||||||
void _updateSelections(int index) {
|
|
||||||
setState(() {
|
|
||||||
_selections[index] = !_selections[index];
|
|
||||||
widget.onChanged(_getSelectedDaysString());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Column(children: [
|
|
||||||
Text('Days', style: Theme.of(context).textTheme.headlineSmall),
|
|
||||||
Expanded(
|
|
||||||
child: ListView(
|
|
||||||
children: List.generate(7, (index) {
|
|
||||||
return SwitchListTile(
|
|
||||||
title: Text(_days[index]),
|
|
||||||
value: _selections[index],
|
|
||||||
onChanged: (value) => _updateSelections(index),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/material.dart' as material;
|
import 'package:flutter/material.dart' as material;
|
||||||
|
import 'package:fmassive/constants.dart';
|
||||||
import 'package:fmassive/database.dart';
|
import 'package:fmassive/database.dart';
|
||||||
import 'package:fmassive/days.dart';
|
|
||||||
import 'package:fmassive/exercises.dart';
|
|
||||||
import 'package:fmassive/main.dart';
|
import 'package:fmassive/main.dart';
|
||||||
import 'package:moor_flutter/moor_flutter.dart';
|
import 'package:moor_flutter/moor_flutter.dart';
|
||||||
|
|
||||||
|
@ -18,6 +17,8 @@ class EditPlanPage extends StatefulWidget {
|
||||||
class _EditPlanPageState extends State<EditPlanPage> {
|
class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
late PlansCompanion plan;
|
late PlansCompanion plan;
|
||||||
List<String?> names = [];
|
List<String?> names = [];
|
||||||
|
List<bool>? daySelections;
|
||||||
|
List<bool>? exerciseSelections;
|
||||||
|
|
||||||
Future<List<String?>> getDistinctNames() async {
|
Future<List<String?>> getDistinctNames() async {
|
||||||
final names = await (db.gymSets.selectOnly(distinct: true)
|
final names = await (db.gymSets.selectOnly(distinct: true)
|
||||||
|
@ -29,10 +30,15 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
final dayList = widget.plan.days.value.split(',');
|
||||||
|
daySelections = weekdayNames.map((day) => dayList.contains(day)).toList();
|
||||||
|
|
||||||
getDistinctNames().then((value) {
|
getDistinctNames().then((value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
names = value;
|
names = value;
|
||||||
|
final exercises = widget.plan.exercises.value.split(',');
|
||||||
|
exerciseSelections =
|
||||||
|
names.map((name) => exercises.contains(name)).toList();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -110,30 +116,45 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> get getChildren {
|
List<Widget> get getChildren {
|
||||||
|
final List<Widget> children = [
|
||||||
|
Text('Days', style: Theme.of(context).textTheme.headlineSmall),
|
||||||
|
];
|
||||||
|
|
||||||
|
final days = List.generate(7, (index) {
|
||||||
|
return SwitchListTile(
|
||||||
|
title: Text(weekdayNames[index]),
|
||||||
|
value: daySelections![index],
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
daySelections![index] = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
final exercises = List.generate(names.length, (index) {
|
||||||
|
return SwitchListTile(
|
||||||
|
title: Text(names[index] ?? ''),
|
||||||
|
value: exerciseSelections![index],
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
exerciseSelections![index] = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
children.addAll(days);
|
||||||
|
children.add(
|
||||||
|
Text('Exercises', style: Theme.of(context).textTheme.headlineSmall),
|
||||||
|
);
|
||||||
|
children.addAll(exercises);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Days(
|
child: ListView(
|
||||||
onChanged: (days) {
|
children: children,
|
||||||
setState(() {
|
))
|
||||||
plan = plan.copyWith(days: Value(days));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
days: plan.days.value,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
names.isNotEmpty
|
|
||||||
? Expanded(
|
|
||||||
child: Exercises(
|
|
||||||
onChanged: (exercises) {
|
|
||||||
setState(() {
|
|
||||||
plan = plan.copyWith(exercises: Value(exercises));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
exercises: plan.exercises.value,
|
|
||||||
names: names,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const CircularProgressIndicator(),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class Exercises extends StatefulWidget {
|
|
||||||
final ValueChanged<String> onChanged;
|
|
||||||
final String? exercises;
|
|
||||||
final List<String?> names;
|
|
||||||
|
|
||||||
const Exercises(
|
|
||||||
{required this.onChanged,
|
|
||||||
required this.exercises,
|
|
||||||
super.key,
|
|
||||||
required this.names});
|
|
||||||
|
|
||||||
@override
|
|
||||||
createState() => _ExercisesState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ExercisesState extends State<Exercises> {
|
|
||||||
late List<bool> _selections;
|
|
||||||
|
|
||||||
@override
|
|
||||||
initState() {
|
|
||||||
super.initState();
|
|
||||||
final exercises = widget.exercises?.split(',');
|
|
||||||
_selections =
|
|
||||||
widget.names.map((name) => exercises?.contains(name) ?? false).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
String _getExercises() {
|
|
||||||
List<String> exercises = [];
|
|
||||||
for (int i = 0; i < _selections.length; i++)
|
|
||||||
if (_selections[i]) exercises.add(widget.names[i] ?? '');
|
|
||||||
return exercises.join(",");
|
|
||||||
}
|
|
||||||
|
|
||||||
void _updateSelections(int index) {
|
|
||||||
setState(() {
|
|
||||||
_selections[index] = !_selections[index];
|
|
||||||
widget.onChanged(_getExercises());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Column(children: [
|
|
||||||
Text('Exercises', style: Theme.of(context).textTheme.headlineSmall),
|
|
||||||
Expanded(
|
|
||||||
child: ListView(
|
|
||||||
children: List.generate(widget.names.length, (index) {
|
|
||||||
return SwitchListTile(
|
|
||||||
title: Text(widget.names[index] ?? ''),
|
|
||||||
value: _selections[index],
|
|
||||||
onChanged: (value) => _updateSelections(index),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user