Fixed Bug: workout is interruptable now

main
Kai Mannweiler 2023-03-03 15:02:27 +01:00
parent 7dd1a748f2
commit 3b25e12d08
4 changed files with 34 additions and 12 deletions

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/providers/page_provider.dart';
import 'package:smoke_cess_app/providers/tasks_provider.dart';
import 'package:smoke_cess_app/providers/workout_provider.dart';
import 'package:smoke_cess_app/services/pages_service.dart';
import 'package:smoke_cess_app/providers/settings_provider.dart';
@ -21,9 +22,11 @@ class MyHomePageState extends State<MyHomePage> {
void _onItemTapped(int index) {
PageProvider pageProvider = context.read<PageProvider>();
WorkoutProvider workoutProvider = context.read<WorkoutProvider>();
setState(() {
if (_isConfigured) {
pageProvider.showForm = false;
workoutProvider.interruptWorkout();
_selectedIndex = index;
return;
}

View File

@ -21,5 +21,6 @@ class TimerProvider extends ChangeNotifier {
void stopTimer() {
started = false;
_timer?.cancel();
_timer = null;
}
}

View File

@ -92,6 +92,14 @@ class WorkoutProvider extends ChangeNotifier {
notifyListeners();
}
void interruptWorkout() {
isWorkoutStarted = false;
isWorkoutComplete = false;
_audioPlayer.stop();
timerProvider.stopTimer();
notifyListeners();
}
void saveWorkout() {
Workout workout =
Workout(motivationBefore, motivationAfter, DateTime.now());

View File

@ -1,7 +1,10 @@
import 'dart:async';
import 'package:awesome_dialog/awesome_dialog.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/providers/page_provider.dart';
import 'package:smoke_cess_app/providers/tasks_provider.dart';
import 'package:smoke_cess_app/providers/workout_provider.dart';
import 'package:smoke_cess_app/services/pages_service.dart';
@ -18,19 +21,29 @@ class WorkoutTimerWidget extends StatelessWidget {
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');
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),
() => showMotivationPopup(context, (double value) {
workoutProvider.motivationAfter = value.toInt();
workoutProvider.saveWorkout();
tasksProvider.setTaskDone(Pages.timer);
}, 'Motivation nach dem Training'));
Timer(const Duration(milliseconds: 1), handleStopWorkout);
}
void handleStartStopWorkout() {
@ -40,11 +53,8 @@ class WorkoutTimerWidget extends StatelessWidget {
workoutProvider.startWorkout();
}, 'Motivation vor dem Training');
} else {
workoutProvider.stopWorkout();
showMotivationPopup(
context,
(double value) => workoutProvider.motivationAfter = value.toInt(),
'Motivation nach dem Training');
workoutProvider.interruptWorkout();
handleStopWorkout();
}
}