94 lines
3.0 KiB
Dart
94 lines
3.0 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:awesome_dialog/awesome_dialog.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../providers/page_provider.dart';
|
|
import '../providers/tasks_provider.dart';
|
|
import '../providers/workout_provider.dart';
|
|
import '../services/pages_service.dart';
|
|
import '../widgets/timer_widget.dart';
|
|
import '../providers/timer_provider.dart';
|
|
import 'popup_for_start_and_stop.dart';
|
|
|
|
class WorkoutTimerWidget extends StatelessWidget {
|
|
const WorkoutTimerWidget({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
TimerProvider timerProvider = context.watch<TimerProvider>();
|
|
WorkoutProvider workoutProvider = context.watch<WorkoutProvider>();
|
|
TasksProvider tasksProvider = context.read<TasksProvider>();
|
|
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');
|
|
if (context.mounted) {
|
|
await AwesomeDialog(
|
|
context: context,
|
|
dialogType: DialogType.success,
|
|
title: 'Gespeichert',
|
|
desc: 'Der Eintrag wurde erfolgreich gespeichert',
|
|
).show();
|
|
pageProvider.swap();
|
|
}
|
|
}
|
|
|
|
if (workoutProvider.isPhaseComplete && !workoutProvider.isWorkoutComplete) {
|
|
Timer(const Duration(milliseconds: 1), () => workoutProvider.nextPhase());
|
|
}
|
|
|
|
if (workoutProvider.isWorkoutComplete) {
|
|
Timer(const Duration(milliseconds: 1), handleStopWorkout);
|
|
}
|
|
|
|
void handleStartStopWorkout() {
|
|
if (!workoutProvider.isWorkoutStarted) {
|
|
showMotivationPopup(context, (double value) {
|
|
workoutProvider.motivationBefore = value.toInt();
|
|
workoutProvider.startWorkout();
|
|
}, 'Motivation vor dem Training');
|
|
} else {
|
|
workoutProvider.interruptWorkout();
|
|
handleStopWorkout();
|
|
}
|
|
}
|
|
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(workoutProvider.currentPhase),
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
SizedBox(
|
|
height: 100,
|
|
width: 100,
|
|
child: CircularProgressIndicator(
|
|
color: workoutProvider.currentPhaseColor,
|
|
value: (workoutProvider.currentPhaseDuration.inSeconds
|
|
.toDouble() -
|
|
timerProvider.elapsedSeconds) /
|
|
workoutProvider.currentPhaseDuration.inSeconds)),
|
|
TimerWidget(duration: workoutProvider.currentPhaseDuration),
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
ElevatedButton(
|
|
onPressed: handleStartStopWorkout,
|
|
child: Text(timerProvider.started ? 'Stop' : 'Start'))
|
|
],
|
|
);
|
|
}
|
|
}
|