Compare commits
3 Commits
a3d7e651f4
...
3983366408
Author | SHA1 | Date | |
---|---|---|---|
3983366408 | |||
3ba7458056 | |||
8678e935df |
|
@ -78,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;
|
||||||
|
@ -86,47 +87,63 @@ 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 {
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
|
|
||||||
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),
|
|
||||||
),
|
|
||||||
),);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> get getChildren {
|
List<Widget> get getChildren {
|
||||||
|
@ -166,9 +183,10 @@ class _EditPlanPageState extends State<EditPlanPage> {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: children,
|
children: children,
|
||||||
),),
|
),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
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:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
@ -23,6 +25,27 @@ class _StartPlanState extends State<StartPlan> {
|
||||||
final repsNode = FocusNode();
|
final repsNode = FocusNode();
|
||||||
final weightController = TextEditingController();
|
final weightController = TextEditingController();
|
||||||
final weightNode = FocusNode();
|
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 {
|
Future<void> getTotals() async {
|
||||||
final query = await (db.selectOnly(db.gymSets)
|
final query = await (db.selectOnly(db.gymSets)
|
||||||
|
@ -79,12 +102,16 @@ class _StartPlanState extends State<StartPlan> {
|
||||||
..limit(1))
|
..limit(1))
|
||||||
.get();
|
.get();
|
||||||
final firstSet = sets.first;
|
final firstSet = sets.first;
|
||||||
repsController.text = firstSet.reps.toString();
|
setState(() {
|
||||||
repsController.selection = TextSelection(
|
repsController.text = firstSet.reps.toString();
|
||||||
baseOffset: 0,
|
repsController.selection = TextSelection(
|
||||||
extentOffset: firstSet.reps.toString().length,
|
baseOffset: 0,
|
||||||
);
|
extentOffset: firstSet.reps.toString().length,
|
||||||
weightController.text = firstSet.weight.toString();
|
);
|
||||||
|
weightController.text = firstSet.weight.toString();
|
||||||
|
minutes = firstSet.minutes;
|
||||||
|
seconds = firstSet.seconds;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -92,16 +119,15 @@ class _StartPlanState extends State<StartPlan> {
|
||||||
super.initState();
|
super.initState();
|
||||||
exercises = widget.plan.exercises.value.split(',');
|
exercises = widget.plan.exercises.value.split(',');
|
||||||
repsNode.requestFocus();
|
repsNode.requestFocus();
|
||||||
|
|
||||||
getCounts();
|
getCounts();
|
||||||
getTotals();
|
getTotals();
|
||||||
|
|
||||||
focus(selectedExercise);
|
focus(selectedExercise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
dispose() {
|
dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
timer?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -167,6 +193,9 @@ class _StartPlanState extends State<StartPlan> {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
LinearProgressIndicator(
|
||||||
|
value: current / (minutes * 60 * 1000 + seconds * 1000),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -180,7 +209,9 @@ class _StartPlanState extends State<StartPlan> {
|
||||||
);
|
);
|
||||||
await db.into(db.gymSets).insert(gymSet);
|
await db.into(db.gymSets).insert(gymSet);
|
||||||
const platform = MethodChannel('com.massive/android');
|
const platform = MethodChannel('com.massive/android');
|
||||||
platform.invokeMethod('timer', [180000]);
|
platform
|
||||||
|
.invokeMethod('timer', [minutes * 60 * 1000 + seconds * 1000]);
|
||||||
|
startTimer();
|
||||||
await getCounts();
|
await getCounts();
|
||||||
},
|
},
|
||||||
child: const Icon(Icons.check),
|
child: const Icon(Icons.check),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user