Add timer to start_plan
This commit is contained in:
parent
8678e935df
commit
3ba7458056
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/material.dart' as material;
|
||||
import 'package:flutter/services.dart';
|
||||
|
@ -23,6 +25,27 @@ class _StartPlanState extends State<StartPlan> {
|
|||
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)
|
||||
|
@ -79,12 +102,16 @@ class _StartPlanState extends State<StartPlan> {
|
|||
..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();
|
||||
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
|
||||
|
@ -92,16 +119,15 @@ class _StartPlanState extends State<StartPlan> {
|
|||
super.initState();
|
||||
exercises = widget.plan.exercises.value.split(',');
|
||||
repsNode.requestFocus();
|
||||
|
||||
getCounts();
|
||||
getTotals();
|
||||
|
||||
focus(selectedExercise);
|
||||
}
|
||||
|
||||
@override
|
||||
dispose() {
|
||||
super.dispose();
|
||||
timer?.cancel();
|
||||
}
|
||||
|
||||
@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);
|
||||
const platform = MethodChannel('com.massive/android');
|
||||
platform.invokeMethod('timer', [180000]);
|
||||
platform
|
||||
.invokeMethod('timer', [minutes * 60 * 1000 + seconds * 1000]);
|
||||
startTimer();
|
||||
await getCounts();
|
||||
},
|
||||
child: const Icon(Icons.check),
|
||||
|
|
Loading…
Reference in New Issue
Block a user