2023-02-28 13:05:51 +01:00
|
|
|
import 'dart:async';
|
|
|
|
|
2023-03-03 15:02:27 +01:00
|
|
|
import 'package:awesome_dialog/awesome_dialog.dart';
|
2023-02-27 01:20:00 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2023-03-03 15:02:27 +01:00
|
|
|
import 'package:smoke_cess_app/providers/page_provider.dart';
|
2023-03-02 20:35:20 +01:00
|
|
|
import 'package:smoke_cess_app/providers/tasks_provider.dart';
|
2023-02-27 01:20:00 +01:00
|
|
|
import 'package:smoke_cess_app/providers/workout_provider.dart';
|
2023-03-02 20:35:20 +01:00
|
|
|
import 'package:smoke_cess_app/services/pages_service.dart';
|
2023-02-27 01:20:00 +01:00
|
|
|
import 'package:smoke_cess_app/widgets/timer_widget.dart';
|
|
|
|
|
|
|
|
import '../providers/timer_provider.dart';
|
2023-03-01 13:30:12 +01:00
|
|
|
import 'popup_for_start_and_stop.dart';
|
2023-02-27 01:20:00 +01:00
|
|
|
|
|
|
|
class WorkoutTimerWidget extends StatelessWidget {
|
|
|
|
const WorkoutTimerWidget({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
TimerProvider timerProvider = context.watch<TimerProvider>();
|
|
|
|
WorkoutProvider workoutProvider = context.watch<WorkoutProvider>();
|
2023-03-02 20:35:20 +01:00
|
|
|
TasksProvider tasksProvider = context.read<TasksProvider>();
|
2023-03-03 15:02:27 +01:00
|
|
|
PageProvider pageProvider = context.read<PageProvider>();
|
|
|
|
|
|
|
|
void handleStopWorkout() async {
|
|
|
|
await showMotivationPopup(context, (double value) {
|
|
|
|
workoutProvider.motivationAfter = value.toInt();
|
|
|
|
workoutProvider.saveWorkout();
|
|
|
|
tasksProvider.setTaskDone(Pages.timer);
|
|
|
|
}, 'Motivation nach dem Training');
|
2023-03-04 10:29:35 +01:00
|
|
|
if (context.mounted) {
|
|
|
|
await AwesomeDialog(
|
|
|
|
context: context,
|
|
|
|
dialogType: DialogType.success,
|
|
|
|
title: 'Gespeichert',
|
|
|
|
desc: 'Der Eintrag wurde erfolgreich gespeichert',
|
|
|
|
).show();
|
|
|
|
pageProvider.swap();
|
|
|
|
}
|
2023-03-03 15:02:27 +01:00
|
|
|
}
|
2023-02-27 01:20:00 +01:00
|
|
|
|
2023-03-02 15:08:39 +01:00
|
|
|
if (workoutProvider.isPhaseComplete && !workoutProvider.isWorkoutComplete) {
|
2023-02-28 13:05:51 +01:00
|
|
|
Timer(const Duration(milliseconds: 1), () => workoutProvider.nextPhase());
|
2023-02-27 01:20:00 +01:00
|
|
|
}
|
|
|
|
|
2023-03-02 16:06:24 +01:00
|
|
|
if (workoutProvider.isWorkoutComplete) {
|
2023-03-03 15:02:27 +01:00
|
|
|
Timer(const Duration(milliseconds: 1), handleStopWorkout);
|
2023-03-02 16:06:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleStartStopWorkout() {
|
2023-03-02 13:19:08 +01:00
|
|
|
if (!workoutProvider.isWorkoutStarted) {
|
2023-03-02 16:06:24 +01:00
|
|
|
showMotivationPopup(context, (double value) {
|
|
|
|
workoutProvider.motivationBefore = value.toInt();
|
|
|
|
workoutProvider.startWorkout();
|
|
|
|
}, 'Motivation vor dem Training');
|
2023-03-02 13:19:08 +01:00
|
|
|
} else {
|
2023-03-03 15:02:27 +01:00
|
|
|
workoutProvider.interruptWorkout();
|
|
|
|
handleStopWorkout();
|
2023-03-02 13:19:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-27 01:20:00 +01:00
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(workoutProvider.currentPhase),
|
2023-03-01 12:57:02 +01:00
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 100,
|
|
|
|
width: 100,
|
|
|
|
child: CircularProgressIndicator(
|
2023-03-01 13:07:01 +01:00
|
|
|
color: workoutProvider.currentPhaseColor,
|
2023-03-01 12:57:02 +01:00
|
|
|
value: (workoutProvider.currentPhaseDuration.inSeconds
|
|
|
|
.toDouble() -
|
|
|
|
timerProvider.elapsedSeconds) /
|
|
|
|
workoutProvider.currentPhaseDuration.inSeconds)),
|
|
|
|
TimerWidget(duration: workoutProvider.currentPhaseDuration),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
2023-02-28 14:58:32 +01:00
|
|
|
ElevatedButton(
|
2023-03-02 13:19:08 +01:00
|
|
|
onPressed: handleStartStopWorkout,
|
2023-02-28 14:58:32 +01:00
|
|
|
child: Text(timerProvider.started ? 'Stop' : 'Start'))
|
2023-02-27 01:20:00 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|