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

View File

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

View File

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

View File

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