Compare commits
26
Commits
4aa6926f5c
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3983366408 | ||
|
|
3ba7458056 | ||
|
|
a3d7e651f4 | ||
|
|
8678e935df | ||
|
|
9aed2b3ac1 | ||
|
|
6908623ba2 | ||
|
|
a9486727b2 | ||
|
|
e4ba71ad4b | ||
|
|
202ec599d6 | ||
|
|
fbffc0cf4a | ||
|
|
19f9dd9b3b | ||
|
|
b6a73c398e | ||
|
|
c5a209d41e | ||
|
|
852d28afcf | ||
|
|
dac65c8390 | ||
|
|
98991a3d02 | ||
|
|
36b8ce37ad | ||
|
|
7642c6faf2 | ||
|
|
b617724f0a | ||
|
|
4a83465d82 | ||
|
|
a383ebfe34 | ||
|
|
e0302e63e2 | ||
|
|
af3fd69688 | ||
|
|
738a48438e | ||
|
|
2849cec682 | ||
|
|
2544a3de9f |
Vendored
+25
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "fmassive",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "fmassive (profile mode)",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"flutterMode": "profile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "fmassive (release mode)",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"flutterMode": "release"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -4,3 +4,4 @@ linter:
|
|||||||
rules:
|
rules:
|
||||||
curly_braces_in_flow_control_structures: false
|
curly_braces_in_flow_control_structures: false
|
||||||
avoid_print: false
|
avoid_print: false
|
||||||
|
require_trailing_commas: true
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
const List<String> weekdayNames = [
|
||||||
|
'Monday',
|
||||||
|
'Tuesday',
|
||||||
|
'Wednesday',
|
||||||
|
'Thursday',
|
||||||
|
'Friday',
|
||||||
|
'Saturday',
|
||||||
|
'Sunday',
|
||||||
|
];
|
||||||
+2
-30
@@ -17,7 +17,7 @@ class MyDatabase extends _$MyDatabase {
|
|||||||
MyDatabase() : super(_openConnection());
|
MyDatabase() : super(_openConnection());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get schemaVersion => 2;
|
int get schemaVersion => 1;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MigrationStrategy get migration => MigrationStrategy(
|
MigrationStrategy get migration => MigrationStrategy(
|
||||||
@@ -27,35 +27,7 @@ class MyDatabase extends _$MyDatabase {
|
|||||||
var data = await (db.select(db.settings)..limit(1)).get();
|
var data = await (db.select(db.settings)..limit(1)).get();
|
||||||
if (data.isEmpty) await db.into(db.settings).insert(defaultSettings);
|
if (data.isEmpty) await db.into(db.settings).insert(defaultSettings);
|
||||||
},
|
},
|
||||||
onUpgrade: (Migrator m, int from, int to) async {
|
onUpgrade: (Migrator m, int from, int to) async {},
|
||||||
if (from == 1) {
|
|
||||||
await m.create(db.gymSets);
|
|
||||||
await db.customInsert('''
|
|
||||||
INSERT INTO gym_sets(id, name, reps, weight, created, unit, hidden, image, sets, minutes, seconds, steps)
|
|
||||||
SELECT id, name, reps, weight, created, unit, hidden, image, sets, minutes, seconds, steps FROM sets
|
|
||||||
''');
|
|
||||||
await m.addColumn(settings, settings.darkColor);
|
|
||||||
await db.customStatement('''
|
|
||||||
UPDATE settings SET dark_color = darkColor
|
|
||||||
''');
|
|
||||||
await m.addColumn(settings, settings.lightColor);
|
|
||||||
await db.customStatement('''
|
|
||||||
UPDATE settings SET light_color = lightColor
|
|
||||||
''');
|
|
||||||
await m.addColumn(settings, settings.showDate);
|
|
||||||
await db.customStatement('''
|
|
||||||
UPDATE settings SET show_date = showDate
|
|
||||||
''');
|
|
||||||
await m.addColumn(settings, settings.showSets);
|
|
||||||
await db.customStatement('''
|
|
||||||
UPDATE settings SET show_sets = showSets
|
|
||||||
''');
|
|
||||||
await m.addColumn(settings, settings.showUnit);
|
|
||||||
await db.customStatement('''
|
|
||||||
UPDATE settings SET show_unit = showUnit
|
|
||||||
''');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fmassive/main.dart';
|
||||||
|
import 'package:moor/moor.dart';
|
||||||
|
|
||||||
|
class DeleteAllSets extends StatelessWidget {
|
||||||
|
const DeleteAllSets({
|
||||||
|
super.key,
|
||||||
|
required this.mounted,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool mounted;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: ElevatedButton(
|
||||||
|
child: const Text("Delete all sets"),
|
||||||
|
onPressed: () async {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text("Delete all sets"),
|
||||||
|
content: const Text(
|
||||||
|
"This will irreversibly destroy all your gym set data. Are you sure?",),
|
||||||
|
actions: <Widget>[
|
||||||
|
ElevatedButton(
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
child: const Text('Delete'),
|
||||||
|
onPressed: () async {
|
||||||
|
await db.gymSets.delete().go();
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Deleted all sets')),);
|
||||||
|
final navigator = Navigator.of(context);
|
||||||
|
navigator.pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,7 +46,7 @@ class _DynamicColorSchemeState extends State<DynamicColorScheme> {
|
|||||||
context,
|
context,
|
||||||
colorScheme.copyWith(
|
colorScheme.copyWith(
|
||||||
primary: color,
|
primary: color,
|
||||||
));
|
),);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+99
-46
@@ -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';
|
||||||
|
|
||||||
@@ -16,8 +15,9 @@ class EditPlanPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _EditPlanPageState extends State<EditPlanPage> {
|
class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
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,14 +29,17 @@ 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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
plan = widget.plan;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -75,7 +78,8 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
List<Widget> actions = [];
|
List<Widget> actions = [];
|
||||||
if (widget.plan.id.present)
|
if (widget.plan.id.present)
|
||||||
actions.add(IconButton(
|
actions.add(
|
||||||
|
IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
bool? confirm = await _showConfirmationDialog(context);
|
bool? confirm = await _showConfirmationDialog(context);
|
||||||
if (!confirm!) return;
|
if (!confirm!) return;
|
||||||
@@ -83,57 +87,106 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
|||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.delete)));
|
icon: const Icon(Icons.delete),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(title: const Text('Edit Plan'), actions: actions),
|
appBar: AppBar(title: const Text('Edit Plan'), actions: actions),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: material.Column(
|
child: material.Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: getChildren,
|
children: getChildren,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: () async {
|
||||||
|
final days = [];
|
||||||
|
for (int i = 0; i < daySelections!.length; i++) {
|
||||||
|
if (daySelections![i]) days.add(weekdayNames[i]);
|
||||||
|
}
|
||||||
|
if (days.isEmpty) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Select days first')),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final exercises = [];
|
||||||
|
for (int i = 0; i < exerciseSelections!.length; i++) {
|
||||||
|
if (exerciseSelections![i]) exercises.add(names[i]);
|
||||||
|
}
|
||||||
|
if (exercises.isEmpty) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Select exercises first')),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newPlan = widget.plan.copyWith(
|
||||||
|
days: Value(days.join(',')),
|
||||||
|
exercises: Value(exercises.join(',')),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (widget.plan.id.present)
|
||||||
|
await db.update(db.plans).replace(newPlan);
|
||||||
|
else {
|
||||||
|
final id = await db.into(db.plans).insert(newPlan);
|
||||||
|
newPlan = newPlan.copyWith(id: Value(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.check),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
);
|
||||||
onPressed: () async {
|
|
||||||
if (plan.id.present)
|
|
||||||
await db.update(db.plans).replace(plan);
|
|
||||||
else
|
|
||||||
await db.into(db.plans).insert(plan);
|
|
||||||
if (!mounted) return;
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
child: const Icon(Icons.check),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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(),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-9
@@ -34,7 +34,7 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||||||
if (gymSet.id.present) {
|
if (gymSet.id.present) {
|
||||||
repsNode.requestFocus();
|
repsNode.requestFocus();
|
||||||
_repsController.selection = TextSelection(
|
_repsController.selection = TextSelection(
|
||||||
baseOffset: 0, extentOffset: _repsController.text.length);
|
baseOffset: 0, extentOffset: _repsController.text.length,);
|
||||||
} else
|
} else
|
||||||
nameNode.requestFocus();
|
nameNode.requestFocus();
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.delete)));
|
icon: const Icon(Icons.delete),),);
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
@@ -72,7 +72,7 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||||||
decoration: const InputDecoration(labelText: 'Name'),
|
decoration: const InputDecoration(labelText: 'Name'),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_nameController.selection = TextSelection(
|
_nameController.selection = TextSelection(
|
||||||
baseOffset: 0, extentOffset: _nameController.text.length);
|
baseOffset: 0, extentOffset: _nameController.text.length,);
|
||||||
},
|
},
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -85,7 +85,7 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||||||
focusNode: repsNode,
|
focusNode: repsNode,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_repsController.selection = TextSelection(
|
_repsController.selection = TextSelection(
|
||||||
baseOffset: 0, extentOffset: _repsController.text.length);
|
baseOffset: 0, extentOffset: _repsController.text.length,);
|
||||||
},
|
},
|
||||||
decoration: const InputDecoration(labelText: 'Reps'),
|
decoration: const InputDecoration(labelText: 'Reps'),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
@@ -102,12 +102,12 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_weightController.selection = TextSelection(
|
_weightController.selection = TextSelection(
|
||||||
baseOffset: 0, extentOffset: _weightController.text.length);
|
baseOffset: 0, extentOffset: _weightController.text.length,);
|
||||||
},
|
},
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
gymSet = gymSet.copyWith(
|
gymSet = gymSet.copyWith(
|
||||||
weight: Value(double.tryParse(value) ?? 0));
|
weight: Value(double.tryParse(value) ?? 0),);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -118,7 +118,7 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (_nameController.text.isEmpty) {
|
if (_nameController.text.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('Please enter a name')));
|
const SnackBar(content: Text('Please enter a name')),);
|
||||||
nameNode.requestFocus();
|
nameNode.requestFocus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,9 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||||||
await db.update(db.gymSets).replace(gymSet);
|
await db.update(db.gymSets).replace(gymSet);
|
||||||
else {
|
else {
|
||||||
await Permission.notification.request();
|
await Permission.notification.request();
|
||||||
await db.into(db.gymSets).insert(gymSet);
|
final newSet = gymSet.copyWith(
|
||||||
|
created: Value(DateTime.now().toIso8601String()),);
|
||||||
|
await db.into(db.gymSets).insert(newSet);
|
||||||
const platform = MethodChannel('com.massive/android');
|
const platform = MethodChannel('com.massive/android');
|
||||||
platform.invokeMethod('timer', [3000]);
|
platform.invokeMethod('timer', [3000]);
|
||||||
}
|
}
|
||||||
@@ -135,6 +137,6 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||||||
},
|
},
|
||||||
child: const Icon(Icons.check),
|
child: const Icon(Icons.check),
|
||||||
),
|
),
|
||||||
));
|
),);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -101,6 +101,6 @@ class _HomePage extends State<HomePage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: getBody(),
|
body: getBody(),
|
||||||
));
|
),);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-11
@@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fmassive/database.dart';
|
import 'package:fmassive/database.dart';
|
||||||
import 'package:fmassive/edit_set.dart';
|
|
||||||
import 'package:fmassive/home_page.dart';
|
import 'package:fmassive/home_page.dart';
|
||||||
|
|
||||||
MyDatabase db = MyDatabase();
|
MyDatabase db = MyDatabase();
|
||||||
@@ -16,20 +15,12 @@ class MyApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
const edit = EditGymSetPage(gymSet: GymSetsCompanion());
|
|
||||||
|
|
||||||
final Map<String, WidgetBuilder> routes = {
|
|
||||||
'/home': (context) => const HomePage(),
|
|
||||||
'/edit-set': (context) => edit,
|
|
||||||
};
|
|
||||||
|
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Gym App',
|
title: 'Massive',
|
||||||
themeMode: ThemeMode.system,
|
themeMode: ThemeMode.system,
|
||||||
|
home: const HomePage(),
|
||||||
darkTheme: ThemeData.dark(),
|
darkTheme: ThemeData.dark(),
|
||||||
theme: ThemeData.light(),
|
theme: ThemeData.light(),
|
||||||
initialRoute: '/home',
|
|
||||||
routes: routes,
|
|
||||||
navigatorKey: navigatorKey,
|
navigatorKey: navigatorKey,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-41
@@ -1,8 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fmassive/constants.dart';
|
||||||
import 'package:fmassive/database.dart';
|
import 'package:fmassive/database.dart';
|
||||||
import 'package:fmassive/edit_plan.dart';
|
import 'package:fmassive/plan_tile.dart';
|
||||||
import 'package:fmassive/main.dart';
|
|
||||||
import 'package:moor_flutter/moor_flutter.dart';
|
|
||||||
|
|
||||||
class PlanList extends StatelessWidget {
|
class PlanList extends StatelessWidget {
|
||||||
const PlanList({
|
const PlanList({
|
||||||
@@ -14,47 +13,12 @@ class PlanList extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final weekday = weekdayNames[DateTime.now().weekday - 1];
|
||||||
|
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: plans.length,
|
itemCount: plans.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return ListTile(
|
return PlanTile(plan: plans[index], weekday: weekday);
|
||||||
title: Text(plans[index].days.replaceAll(',', ', ')),
|
|
||||||
subtitle: Text(plans[index].exercises),
|
|
||||||
onLongPress: () => showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('Delete set'),
|
|
||||||
content: Text(
|
|
||||||
'Are you sure you want to delete ${plans[index].days}?'),
|
|
||||||
actions: <Widget>[
|
|
||||||
ElevatedButton(
|
|
||||||
child: const Text('Cancel'),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
child: const Text('Delete'),
|
|
||||||
onPressed: () async {
|
|
||||||
final navigator = Navigator.of(context);
|
|
||||||
await db.plans.deleteOne(plans[index]);
|
|
||||||
navigator.pop();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
onTap: () async {
|
|
||||||
await Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) =>
|
|
||||||
EditPlanPage(plan: plans[index].toCompanion(false)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fmassive/database.dart';
|
||||||
|
import 'package:fmassive/edit_plan.dart';
|
||||||
|
import 'package:fmassive/main.dart';
|
||||||
|
import 'package:fmassive/start_plan.dart';
|
||||||
|
import 'package:moor_flutter/moor_flutter.dart';
|
||||||
|
|
||||||
|
class PlanTile extends StatelessWidget {
|
||||||
|
PlanTile({
|
||||||
|
super.key,
|
||||||
|
required this.plan,
|
||||||
|
required this.weekday,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Plan plan;
|
||||||
|
final String weekday;
|
||||||
|
final tapPosition = GlobalKey();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MenuAnchor(
|
||||||
|
menuChildren: [
|
||||||
|
MenuItemButton(
|
||||||
|
child: const Text("Edit"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
EditPlanPage(plan: plan.toCompanion(false)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
MenuItemButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await db.plans.deleteOne(plan);
|
||||||
|
},
|
||||||
|
child: const Text("Delete"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
builder: (context, controller, child) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(
|
||||||
|
plan.days.replaceAll(',', ', '),
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: plan.days.contains(weekday) ? FontWeight.bold : null,
|
||||||
|
decoration:
|
||||||
|
plan.days.contains(weekday) ? TextDecoration.underline : null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
subtitle: Text(plan.exercises),
|
||||||
|
onLongPress: () {
|
||||||
|
controller.open();
|
||||||
|
},
|
||||||
|
onTap: () async {
|
||||||
|
await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => StartPlan(plan: plan.toCompanion(false)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-7
@@ -21,7 +21,7 @@ class PlansPage extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PlansPage extends StatefulWidget {
|
class _PlansPage extends StatefulWidget {
|
||||||
const _PlansPage({super.key, required this.search});
|
const _PlansPage({required this.search});
|
||||||
|
|
||||||
final String search;
|
final String search;
|
||||||
|
|
||||||
@@ -73,14 +73,13 @@ class _PlansPageState extends State<_PlansPage> {
|
|||||||
child: Text(
|
child: Text(
|
||||||
'Error: ${snapshot.error}',
|
'Error: ${snapshot.error}',
|
||||||
style: Theme.of(context).textTheme.headlineSmall,
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
)),
|
),),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (plans == null)
|
if (plans == null) return Container();
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
|
|
||||||
return PlanList(plans: plans);
|
return PlanList(plans: plans);
|
||||||
}),
|
},),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
@@ -88,10 +87,10 @@ class _PlansPageState extends State<_PlansPage> {
|
|||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => const EditPlanPage(
|
builder: (context) => const EditPlanPage(
|
||||||
plan: PlansCompanion(
|
plan: PlansCompanion(
|
||||||
days: Value(''), exercises: Value(''))),
|
days: Value(''), exercises: Value(''),),),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Icon(Icons.add)));
|
child: const Icon(Icons.add),),);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-10
@@ -69,10 +69,6 @@ class _SetList extends State<SetList> {
|
|||||||
pagingController: pagingController,
|
pagingController: pagingController,
|
||||||
gymSet: gymSet,
|
gymSet: gymSet,
|
||||||
),
|
),
|
||||||
firstPageProgressIndicatorBuilder: (_) =>
|
|
||||||
const Center(child: CircularProgressIndicator()),
|
|
||||||
newPageProgressIndicatorBuilder: (_) =>
|
|
||||||
const Center(child: CircularProgressIndicator()),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
@@ -80,13 +76,12 @@ class _SetList extends State<SetList> {
|
|||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => EditGymSetPage(
|
builder: (context) => const EditGymSetPage(
|
||||||
gymSet: GymSetsCompanion(
|
gymSet: GymSetsCompanion(
|
||||||
name: const Value(''),
|
name: Value(''),
|
||||||
reps: const Value(0),
|
reps: Value(0),
|
||||||
weight: const Value(0),
|
weight: Value(0),
|
||||||
image: const Value(''),
|
image: Value(''),
|
||||||
created: Value(DateTime.now().toString()),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
+4
-5
@@ -20,10 +20,9 @@ class SetTile extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(gymSet.name),
|
title: Text(gymSet.name),
|
||||||
subtitle: Text("${gymSet.reps} x ${gymSet.weight}kg"),
|
subtitle: Text(DateFormat("yyyy-MM-dd HH:mm")
|
||||||
trailing: Text(
|
.format(DateTime.parse(gymSet.created)),),
|
||||||
DateFormat("yyyy-MM-dd").format(DateTime.parse(gymSet.created)),
|
trailing: Text("${gymSet.reps} x ${gymSet.weight}kg"),
|
||||||
),
|
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
context,
|
context,
|
||||||
@@ -41,7 +40,7 @@ class SetTile extends StatelessWidget {
|
|||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text('Delete set'),
|
title: const Text('Delete set'),
|
||||||
content: Text(
|
content: Text(
|
||||||
'Are you sure you want to delete ${gymSet.name} ${gymSet.reps}x${gymSet.weight}${gymSet.unit}?'),
|
'Are you sure you want to delete ${gymSet.name} ${gymSet.reps}x${gymSet.weight}${gymSet.unit}?',),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
child: const Text('Cancel'),
|
child: const Text('Cancel'),
|
||||||
|
|||||||
+48
-29
@@ -1,14 +1,15 @@
|
|||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:csv/csv.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
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/database.dart';
|
import 'package:fmassive/database.dart';
|
||||||
|
import 'package:fmassive/delete_all_sets.dart';
|
||||||
import 'package:fmassive/main.dart';
|
import 'package:fmassive/main.dart';
|
||||||
import 'package:fmassive/sound_picker.dart';
|
import 'package:fmassive/sound_picker.dart';
|
||||||
import 'package:moor/moor.dart';
|
import 'package:moor/moor.dart';
|
||||||
import 'package:path/path.dart';
|
|
||||||
import 'package:sqflite/sqflite.dart';
|
|
||||||
|
|
||||||
class SettingsPage extends StatelessWidget {
|
class SettingsPage extends StatelessWidget {
|
||||||
const SettingsPage({super.key, required this.search});
|
const SettingsPage({super.key, required this.search});
|
||||||
@@ -26,7 +27,7 @@ class SettingsPage extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsPage extends StatefulWidget {
|
class _SettingsPage extends StatefulWidget {
|
||||||
const _SettingsPage({super.key, required this.search});
|
const _SettingsPage({required this.search});
|
||||||
|
|
||||||
final String search;
|
final String search;
|
||||||
|
|
||||||
@@ -52,8 +53,7 @@ class _SettingsPageState extends State<_SettingsPage> {
|
|||||||
final settings = snapshot.data;
|
final settings = snapshot.data;
|
||||||
print('build: $settings');
|
print('build: $settings');
|
||||||
|
|
||||||
if (settings == null)
|
if (settings == null) return Container();
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
|
|
||||||
final filteredItems = [
|
final filteredItems = [
|
||||||
{'title': 'Alarm', 'value': settings.alarm},
|
{'title': 'Alarm', 'value': settings.alarm},
|
||||||
@@ -63,11 +63,12 @@ class _SettingsPageState extends State<_SettingsPage> {
|
|||||||
{'title': 'Show Unit', 'value': settings.showUnit},
|
{'title': 'Show Unit', 'value': settings.showUnit},
|
||||||
{'title': 'Steps', 'value': settings.steps},
|
{'title': 'Steps', 'value': settings.steps},
|
||||||
{'title': 'Sound', 'value': settings.sound},
|
{'title': 'Sound', 'value': settings.sound},
|
||||||
{'title': 'Import', 'value': settings.sound},
|
{'title': 'Import sets', 'value': null},
|
||||||
|
{'title': 'Delete all sets', 'value': null},
|
||||||
]
|
]
|
||||||
.where((item) => (item['title'] as String)
|
.where((item) => (item['title'] as String)
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(widget.search.toLowerCase()))
|
.contains(widget.search.toLowerCase()),)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return material.Column(
|
return material.Column(
|
||||||
@@ -78,29 +79,47 @@ class _SettingsPageState extends State<_SettingsPage> {
|
|||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final item = filteredItems[index];
|
final item = filteredItems[index];
|
||||||
|
|
||||||
if (item['title'] == 'Import')
|
if (item['title'] == 'Delete all sets')
|
||||||
|
return DeleteAllSets(mounted: mounted);
|
||||||
|
|
||||||
|
if (item['title'] == 'Import sets')
|
||||||
return Center(
|
return Center(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () async {
|
child: const Text("Import sets"),
|
||||||
final result =
|
onPressed: () async {
|
||||||
await FilePicker.platform.pickFiles(
|
final result = await FilePicker.platform.pickFiles(
|
||||||
type: FileType.any,
|
type: FileType.custom,
|
||||||
);
|
allowedExtensions: ['csv'],);
|
||||||
if (result == null) return;
|
if (result == null) return;
|
||||||
|
|
||||||
final file = File(result.files.single.path!);
|
final file = File(result.files.single.path!);
|
||||||
final path = await getDatabasesPath();
|
final input = file.openRead();
|
||||||
final to = join(path, 'massive.db');
|
final fields = await input
|
||||||
await db.close();
|
.transform(utf8.decoder)
|
||||||
await file.copy(to);
|
.transform(const CsvToListConverter(eol: "\n"))
|
||||||
print('Migrating...');
|
.skip(1)
|
||||||
db = MyDatabase();
|
.toList();
|
||||||
// ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
|
final gymSets = fields.map((row) => GymSetsCompanion(
|
||||||
final migrator = db.createMigrator();
|
id: Value(int.tryParse(row[0]) ?? 0),
|
||||||
await migrator.createAll();
|
name: Value(row[1]),
|
||||||
print('Migrated.');
|
reps: Value(int.tryParse(row[2]) ?? 0),
|
||||||
},
|
weight: Value(double.tryParse(row[3]) ?? 0),
|
||||||
child: const Text("Import")));
|
created: Value(row[4]),
|
||||||
|
unit: Value(row[5]),
|
||||||
|
hidden: Value(row[6] == 'true'),
|
||||||
|
image: Value(row[7]),
|
||||||
|
sets: Value(int.tryParse(row[8]) ?? 0),
|
||||||
|
minutes: Value(int.tryParse(row[9]) ?? 0),
|
||||||
|
seconds: Value(int.tryParse(row[10]) ?? 0),
|
||||||
|
steps: Value(row[11]),
|
||||||
|
),);
|
||||||
|
await db.batch(
|
||||||
|
(batch) => batch.insertAll(db.gymSets, gymSets),);
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Imported sets')),);
|
||||||
|
},
|
||||||
|
),);
|
||||||
|
|
||||||
if (item['title'] == 'Sound') {
|
if (item['title'] == 'Sound') {
|
||||||
return Center(
|
return Center(
|
||||||
@@ -127,7 +146,7 @@ class _SettingsPageState extends State<_SettingsPage> {
|
|||||||
break;
|
break;
|
||||||
case 'Vibrate':
|
case 'Vibrate':
|
||||||
db.update(db.settings).write(
|
db.update(db.settings).write(
|
||||||
SettingsCompanion(vibrate: Value(value)));
|
SettingsCompanion(vibrate: Value(value)),);
|
||||||
break;
|
break;
|
||||||
case 'Notify':
|
case 'Notify':
|
||||||
db
|
db
|
||||||
@@ -141,7 +160,7 @@ class _SettingsPageState extends State<_SettingsPage> {
|
|||||||
break;
|
break;
|
||||||
case 'Show Unit':
|
case 'Show Unit':
|
||||||
db.update(db.settings).write(
|
db.update(db.settings).write(
|
||||||
SettingsCompanion(showUnit: Value(value)));
|
SettingsCompanion(showUnit: Value(value)),);
|
||||||
break;
|
break;
|
||||||
case 'Steps':
|
case 'Steps':
|
||||||
db
|
db
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class _SoundPickerState extends State<SoundPicker> {
|
|||||||
},
|
},
|
||||||
child: Text(widget.path != null
|
child: Text(widget.path != null
|
||||||
? "Sound: ${basename(widget.path!)}"
|
? "Sound: ${basename(widget.path!)}"
|
||||||
: 'Alarm sound'),
|
: 'Alarm sound',),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,222 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/material.dart' as material;
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:fmassive/database.dart';
|
||||||
|
import 'package:fmassive/main.dart';
|
||||||
|
import 'package:moor_flutter/moor_flutter.dart';
|
||||||
|
|
||||||
|
class StartPlan extends StatefulWidget {
|
||||||
|
final PlansCompanion plan;
|
||||||
|
|
||||||
|
const StartPlan({required this.plan, super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
createState() => _StartPlanState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StartPlanState extends State<StartPlan> {
|
||||||
|
late List<String> exercises;
|
||||||
|
List<int> counts = [];
|
||||||
|
List<int> totals = [];
|
||||||
|
int selectedExercise = 0;
|
||||||
|
final repsController = TextEditingController();
|
||||||
|
final repsNode = FocusNode();
|
||||||
|
final weightController = TextEditingController();
|
||||||
|
final weightNode = FocusNode();
|
||||||
|
int current = 0;
|
||||||
|
int minutes = 3;
|
||||||
|
int seconds = 30;
|
||||||
|
Timer? timer;
|
||||||
|
|
||||||
|
void startTimer() {
|
||||||
|
setState(() {
|
||||||
|
current = minutes * 60 * 1000 + seconds * 1000;
|
||||||
|
});
|
||||||
|
timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||||
|
print("StartPlan: current=$current");
|
||||||
|
if (current == 0)
|
||||||
|
setState(() {
|
||||||
|
timer.cancel();
|
||||||
|
});
|
||||||
|
else
|
||||||
|
setState(() {
|
||||||
|
current -= 1000;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> getTotals() async {
|
||||||
|
final query = await (db.selectOnly(db.gymSets)
|
||||||
|
..addColumns([db.gymSets.name, db.gymSets.sets])
|
||||||
|
..where(db.gymSets.name.isIn(exercises))
|
||||||
|
..groupBy([db.gymSets.name, db.gymSets.sets]))
|
||||||
|
.map(
|
||||||
|
(row) =>
|
||||||
|
MapEntry(row.read(db.gymSets.name), row.read(db.gymSets.sets)),
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
final map = Map.fromIterables(
|
||||||
|
query.map((entry) => entry.key),
|
||||||
|
query.map((entry) => entry.value),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
totals = [];
|
||||||
|
for (var exercise in exercises) {
|
||||||
|
totals.add(map[exercise] ?? 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
print("totals=$totals");
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> getCounts() async {
|
||||||
|
var countExp = db.gymSets.name.count();
|
||||||
|
final today = DateTime.now().toIso8601String().split('T')[0];
|
||||||
|
final query = await (db.selectOnly(db.gymSets)
|
||||||
|
..addColumns([countExp, db.gymSets.name])
|
||||||
|
..where(db.gymSets.created.contains(today))
|
||||||
|
..groupBy([db.gymSets.name]))
|
||||||
|
.map((row) => MapEntry(row.read(db.gymSets.name), row.read(countExp)))
|
||||||
|
.get();
|
||||||
|
final map = Map.fromIterables(
|
||||||
|
query.map((entry) => entry.key),
|
||||||
|
query.map((entry) => entry.value),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
counts = [];
|
||||||
|
for (var exercise in exercises) {
|
||||||
|
counts.add(map[exercise] ?? 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
print("counts=$counts");
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> focus(int index) async {
|
||||||
|
final name = exercises[index];
|
||||||
|
final sets = await (db.gymSets.select()
|
||||||
|
..where((gymSet) => gymSet.name.contains(name))
|
||||||
|
..orderBy([
|
||||||
|
(u) => OrderingTerm(expression: u.created, mode: OrderingMode.desc),
|
||||||
|
])
|
||||||
|
..limit(1))
|
||||||
|
.get();
|
||||||
|
final firstSet = sets.first;
|
||||||
|
setState(() {
|
||||||
|
repsController.text = firstSet.reps.toString();
|
||||||
|
repsController.selection = TextSelection(
|
||||||
|
baseOffset: 0,
|
||||||
|
extentOffset: firstSet.reps.toString().length,
|
||||||
|
);
|
||||||
|
weightController.text = firstSet.weight.toString();
|
||||||
|
minutes = firstSet.minutes;
|
||||||
|
seconds = firstSet.seconds;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
exercises = widget.plan.exercises.value.split(',');
|
||||||
|
repsNode.requestFocus();
|
||||||
|
getCounts();
|
||||||
|
getTotals();
|
||||||
|
focus(selectedExercise);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
dispose() {
|
||||||
|
super.dispose();
|
||||||
|
timer?.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (totals.isEmpty || counts.isEmpty) return Container();
|
||||||
|
|
||||||
|
return SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Start plan')),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: material.Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemBuilder: ((context, index) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(exercises[index]),
|
||||||
|
subtitle: Text("${counts[index]}/${totals[index]}"),
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
selectedExercise = index;
|
||||||
|
focus(index);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
leading: Radio<int>(
|
||||||
|
value: index,
|
||||||
|
groupValue: selectedExercise,
|
||||||
|
onChanged: (value) {
|
||||||
|
print("onChanged $value");
|
||||||
|
if (value == null) return;
|
||||||
|
setState(() {
|
||||||
|
selectedExercise = value;
|
||||||
|
focus(index);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
itemCount: exercises.length,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextFormField(
|
||||||
|
decoration: const InputDecoration(labelText: 'Reps'),
|
||||||
|
controller: repsController,
|
||||||
|
focusNode: repsNode,
|
||||||
|
onTap: () {
|
||||||
|
repsController.selection = TextSelection(
|
||||||
|
baseOffset: 0,
|
||||||
|
extentOffset: repsController.text.length,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextFormField(
|
||||||
|
decoration: const InputDecoration(labelText: 'Weight'),
|
||||||
|
controller: weightController,
|
||||||
|
focusNode: weightNode,
|
||||||
|
onTap: () {
|
||||||
|
weightController.selection = TextSelection(
|
||||||
|
baseOffset: 0,
|
||||||
|
extentOffset: weightController.text.length,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
LinearProgressIndicator(
|
||||||
|
value: current / (minutes * 60 * 1000 + seconds * 1000),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: () async {
|
||||||
|
final gymSet = GymSetsCompanion(
|
||||||
|
created: Value(DateTime.now().toIso8601String()),
|
||||||
|
name: Value(exercises[selectedExercise]),
|
||||||
|
reps: Value(int.tryParse(repsController.text) ?? 0),
|
||||||
|
weight: Value(double.tryParse(weightController.text) ?? 0),
|
||||||
|
);
|
||||||
|
await db.into(db.gymSets).insert(gymSet);
|
||||||
|
const platform = MethodChannel('com.massive/android');
|
||||||
|
platform
|
||||||
|
.invokeMethod('timer', [minutes * 60 * 1000 + seconds * 1000]);
|
||||||
|
startTimer();
|
||||||
|
await getCounts();
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.check),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -241,6 +241,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.3"
|
version: "3.0.3"
|
||||||
|
csv:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: csv
|
||||||
|
sha256: "63ed2871dd6471193dffc52c0e6c76fb86269c00244d244297abbb355c84a86e"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.1.1"
|
||||||
cupertino_icons:
|
cupertino_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ dependencies:
|
|||||||
intl: ^0.18.0
|
intl: ^0.18.0
|
||||||
permission_handler: ^11.0.1
|
permission_handler: ^11.0.1
|
||||||
infinite_scroll_pagination: ^4.0.0
|
infinite_scroll_pagination: ^4.0.0
|
||||||
|
csv: ^5.1.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ bool FlutterWindow::OnCreate() {
|
|||||||
this->Show();
|
this->Show();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Flutter can complete the first frame before the "show window" callback is
|
||||||
|
// registered. The following call ensures a frame is pending to ensure the
|
||||||
|
// window is shown. It is a no-op if the first frame hasn't completed yet.
|
||||||
|
flutter_controller_->ForceRedraw();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user