Compare commits
15 Commits
4aa6926f5c
...
b6a73c398e
Author | SHA1 | Date | |
---|---|---|---|
b6a73c398e | |||
c5a209d41e | |||
852d28afcf | |||
dac65c8390 | |||
98991a3d02 | |||
36b8ce37ad | |||
7642c6faf2 | |||
b617724f0a | |||
4a83465d82 | |||
a383ebfe34 | |||
e0302e63e2 | |||
af3fd69688 | |||
738a48438e | |||
2849cec682 | |||
2544a3de9f |
25
.vscode/launch.json
vendored
Normal file
25
.vscode/launch.json
vendored
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
9
lib/constants.dart
Normal file
9
lib/constants.dart
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
const List<String> weekdayNames = [
|
||||||
|
'Monday',
|
||||||
|
'Tuesday',
|
||||||
|
'Wednesday',
|
||||||
|
'Thursday',
|
||||||
|
'Friday',
|
||||||
|
'Saturday',
|
||||||
|
'Sunday',
|
||||||
|
];
|
|
@ -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),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
51
lib/delete_all_sets.dart
Normal file
51
lib/delete_all_sets.dart
Normal file
|
@ -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();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -97,10 +103,24 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
final days = [];
|
||||||
|
for (int i = 0; i < daySelections!.length; i++) {
|
||||||
|
if (daySelections![i]) days.add(weekdayNames[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
final exercises = [];
|
||||||
|
for (int i = 0; i < exerciseSelections!.length; i++) {
|
||||||
|
if (exerciseSelections![i]) exercises.add(names[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
final newPlan = plan.copyWith(
|
||||||
|
days: Value(days.join(',')),
|
||||||
|
exercises: Value(exercises.join(',')));
|
||||||
|
|
||||||
if (plan.id.present)
|
if (plan.id.present)
|
||||||
await db.update(db.plans).replace(plan);
|
await db.update(db.plans).replace(newPlan);
|
||||||
else
|
else
|
||||||
await db.into(db.plans).insert(plan);
|
await db.into(db.plans).insert(newPlan);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
|
@ -110,30 +130,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(),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
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/edit_plan.dart';
|
||||||
import 'package:fmassive/main.dart';
|
import 'package:fmassive/main.dart';
|
||||||
|
import 'package:fmassive/start_plan.dart';
|
||||||
import 'package:moor_flutter/moor_flutter.dart';
|
import 'package:moor_flutter/moor_flutter.dart';
|
||||||
|
|
||||||
class PlanList extends StatelessWidget {
|
class PlanList extends StatelessWidget {
|
||||||
|
@ -14,11 +16,20 @@ 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 ListTile(
|
||||||
title: Text(plans[index].days.replaceAll(',', ', ')),
|
title: Text(plans[index].days.replaceAll(',', ', '),
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: plans[index].days.contains(weekday)
|
||||||
|
? FontWeight.bold
|
||||||
|
: null,
|
||||||
|
decoration: plans[index].days.contains(weekday)
|
||||||
|
? TextDecoration.underline
|
||||||
|
: null)),
|
||||||
subtitle: Text(plans[index].exercises),
|
subtitle: Text(plans[index].exercises),
|
||||||
onLongPress: () => showDialog(
|
onLongPress: () => showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -51,7 +62,7 @@ class PlanList extends StatelessWidget {
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
EditPlanPage(plan: plans[index].toCompanion(false)),
|
StartPlan(plan: plans[index].toCompanion(false)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -80,13 +80,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()),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
@ -63,7 +64,8 @@ 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()
|
||||||
|
@ -78,29 +80,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(
|
||||||
|
child: const Text("Import sets"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final result =
|
final result = await FilePicker.platform.pickFiles(
|
||||||
await FilePicker.platform.pickFiles(
|
type: FileType.custom,
|
||||||
type: FileType.any,
|
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),
|
||||||
|
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')));
|
||||||
},
|
},
|
||||||
child: const Text("Import")));
|
));
|
||||||
|
|
||||||
if (item['title'] == 'Sound') {
|
if (item['title'] == 'Sound') {
|
||||||
return Center(
|
return Center(
|
||||||
|
|
184
lib/start_plan.dart
Normal file
184
lib/start_plan.dart
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
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/edit_plan.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();
|
||||||
|
|
||||||
|
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;
|
||||||
|
repsController.text = firstSet.reps.toString();
|
||||||
|
repsController.selection = TextSelection(
|
||||||
|
baseOffset: 0, extentOffset: firstSet.reps.toString().length);
|
||||||
|
weightController.text = firstSet.weight.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
exercises = widget.plan.exercises.value.split(',');
|
||||||
|
repsNode.requestFocus();
|
||||||
|
|
||||||
|
getCounts();
|
||||||
|
getTotals();
|
||||||
|
|
||||||
|
focus(selectedExercise);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
dispose() {
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
List<Widget> actions = [];
|
||||||
|
if (widget.plan.id.present)
|
||||||
|
actions.add(IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => EditPlanPage(plan: widget.plan),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.edit)));
|
||||||
|
|
||||||
|
if (totals.isEmpty || counts.isEmpty)
|
||||||
|
return const CircularProgressIndicator();
|
||||||
|
|
||||||
|
return SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Start plan'), actions: actions),
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
TextFormField(
|
||||||
|
decoration: const InputDecoration(labelText: 'Weight'),
|
||||||
|
controller: weightController,
|
||||||
|
focusNode: weightNode,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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', [180000]);
|
||||||
|
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:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user