Compare commits
No commits in common. "b6a73c398efd90cd54111e4945b67c9cbeed0601" and "4aa6926f5ca953eeaf4aeba9be1be9638b607f09" have entirely different histories.
b6a73c398e
...
4aa6926f5c
25
.vscode/launch.json
vendored
25
.vscode/launch.json
vendored
|
@ -1,25 +0,0 @@
|
||||||
{
|
|
||||||
// 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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
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 => 1;
|
int get schemaVersion => 2;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MigrationStrategy get migration => MigrationStrategy(
|
MigrationStrategy get migration => MigrationStrategy(
|
||||||
|
@ -27,7 +27,35 @@ 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
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
63
lib/days.dart
Normal file
63
lib/days.dart
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
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,51 +0,0 @@
|
||||||
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,7 +1,8 @@
|
||||||
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';
|
||||||
|
|
||||||
|
@ -17,8 +18,6 @@ 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)
|
||||||
|
@ -30,15 +29,10 @@ 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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -103,24 +97,10 @@ 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(newPlan);
|
await db.update(db.plans).replace(plan);
|
||||||
else
|
else
|
||||||
await db.into(db.plans).insert(newPlan);
|
await db.into(db.plans).insert(plan);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
|
@ -130,45 +110,30 @@ 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: ListView(
|
child: Days(
|
||||||
children: children,
|
onChanged: (days) {
|
||||||
))
|
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,9 +126,7 @@ 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();
|
||||||
final newSet = gymSet.copyWith(
|
await db.into(db.gymSets).insert(gymSet);
|
||||||
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]);
|
||||||
}
|
}
|
||||||
|
|
60
lib/exercises.dart
Normal file
60
lib/exercises.dart
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
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,5 +1,6 @@
|
||||||
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();
|
||||||
|
@ -15,12 +16,20 @@ 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: 'Massive',
|
title: 'Gym App',
|
||||||
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,9 +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/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 {
|
||||||
|
@ -16,20 +14,11 @@ 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,
|
||||||
|
@ -62,7 +51,7 @@ class PlanList extends StatelessWidget {
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
StartPlan(plan: plans[index].toCompanion(false)),
|
EditPlanPage(plan: plans[index].toCompanion(false)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,7 +21,7 @@ class PlansPage extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PlansPage extends StatefulWidget {
|
class _PlansPage extends StatefulWidget {
|
||||||
const _PlansPage({required this.search});
|
const _PlansPage({super.key, required this.search});
|
||||||
|
|
||||||
final String search;
|
final String search;
|
||||||
|
|
||||||
|
|
|
@ -80,12 +80,13 @@ class _SetList extends State<SetList> {
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => const EditGymSetPage(
|
builder: (context) => EditGymSetPage(
|
||||||
gymSet: GymSetsCompanion(
|
gymSet: GymSetsCompanion(
|
||||||
name: Value(''),
|
name: const Value(''),
|
||||||
reps: Value(0),
|
reps: const Value(0),
|
||||||
weight: Value(0),
|
weight: const Value(0),
|
||||||
image: Value(''),
|
image: const Value(''),
|
||||||
|
created: Value(DateTime.now().toString()),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -20,9 +20,10 @@ 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(DateFormat("yyyy-MM-dd HH:mm")
|
subtitle: Text("${gymSet.reps} x ${gymSet.weight}kg"),
|
||||||
.format(DateTime.parse(gymSet.created))),
|
trailing: Text(
|
||||||
trailing: Text("${gymSet.reps} x ${gymSet.weight}kg"),
|
DateFormat("yyyy-MM-dd").format(DateTime.parse(gymSet.created)),
|
||||||
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
context,
|
context,
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
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});
|
||||||
|
@ -27,7 +26,7 @@ class SettingsPage extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsPage extends StatefulWidget {
|
class _SettingsPage extends StatefulWidget {
|
||||||
const _SettingsPage({required this.search});
|
const _SettingsPage({super.key, required this.search});
|
||||||
|
|
||||||
final String search;
|
final String search;
|
||||||
|
|
||||||
|
@ -64,8 +63,7 @@ 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 sets', 'value': null},
|
{'title': 'Import', 'value': settings.sound},
|
||||||
{'title': 'Delete all sets', 'value': null},
|
|
||||||
]
|
]
|
||||||
.where((item) => (item['title'] as String)
|
.where((item) => (item['title'] as String)
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
|
@ -80,47 +78,29 @@ class _SettingsPageState extends State<_SettingsPage> {
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final item = filteredItems[index];
|
final item = filteredItems[index];
|
||||||
|
|
||||||
if (item['title'] == 'Delete all sets')
|
if (item['title'] == 'Import')
|
||||||
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 = await FilePicker.platform.pickFiles(
|
final result =
|
||||||
type: FileType.custom,
|
await FilePicker.platform.pickFiles(
|
||||||
allowedExtensions: ['csv']);
|
type: FileType.any,
|
||||||
|
);
|
||||||
if (result == null) return;
|
if (result == null) return;
|
||||||
|
|
||||||
final file = File(result.files.single.path!);
|
final file = File(result.files.single.path!);
|
||||||
final input = file.openRead();
|
final path = await getDatabasesPath();
|
||||||
final fields = await input
|
final to = join(path, 'massive.db');
|
||||||
.transform(utf8.decoder)
|
await db.close();
|
||||||
.transform(const CsvToListConverter(eol: "\n"))
|
await file.copy(to);
|
||||||
.skip(1)
|
print('Migrating...');
|
||||||
.toList();
|
db = MyDatabase();
|
||||||
final gymSets = fields.map((row) => GymSetsCompanion(
|
// ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
|
||||||
id: Value(int.tryParse(row[0]) ?? 0),
|
final migrator = db.createMigrator();
|
||||||
name: Value(row[1]),
|
await migrator.createAll();
|
||||||
reps: Value(int.tryParse(row[2]) ?? 0),
|
print('Migrated.');
|
||||||
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(
|
||||||
|
|
|
@ -1,184 +0,0 @@
|
||||||
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,14 +241,6 @@ 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,7 +47,6 @@ 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