diff --git a/lib/pages/interval_page.dart b/lib/pages/interval_page.dart index f6d2fcd..74ccffa 100644 --- a/lib/pages/interval_page.dart +++ b/lib/pages/interval_page.dart @@ -3,8 +3,10 @@ import 'package:audioplayers/audioplayers.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/providers/timer_provider.dart'; +import 'package:smoke_cess_app/providers/workout_provider.dart'; import 'package:smoke_cess_app/widgets/popup_for_start_and_stop.dart'; import 'package:smoke_cess_app/widgets/timer_widget.dart'; +import 'package:smoke_cess_app/widgets/workout_timer_widget.dart'; import '../providers/input_provider.dart'; @@ -168,7 +170,14 @@ class _IntervalTimerPageState extends State { @override Widget build(BuildContext context) { - return ChangeNotifierProvider( + return MultiProvider( + providers: [ + ChangeNotifierProvider(create: (context) => TimerProvider()), + ChangeNotifierProvider(create: (context) => WorkoutProvider()) + ], + child: WorkoutTimerWidget(), + ); + ChangeNotifierProvider( create: (context) => TimerProvider(), child: TimerWidget( duration: Duration(seconds: 5), diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 2af4f13..9b6127f 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -15,7 +15,7 @@ class MyHomePage extends StatefulWidget { } class MyHomePageState extends State { - int _selectedIndex = 4; + int _selectedIndex = 2; int? _gruppe; final List _titles = [ diff --git a/lib/providers/timer_provider.dart b/lib/providers/timer_provider.dart index 0601b39..f5a7689 100644 --- a/lib/providers/timer_provider.dart +++ b/lib/providers/timer_provider.dart @@ -9,9 +9,9 @@ class TimerProvider extends ChangeNotifier { void startTimer(Duration duration) { started = true; - print('starting timer'); _timer = Timer.periodic(const Duration(seconds: 1), ((timer) { if (timer.tick >= duration.inSeconds) { + print(elapsedSeconds); timer.cancel(); started = false; } diff --git a/lib/providers/workout_provider.dart b/lib/providers/workout_provider.dart new file mode 100644 index 0000000..0505347 --- /dev/null +++ b/lib/providers/workout_provider.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; + +class WorkoutProvider extends ChangeNotifier { + final List _workoutPhases = [ + 'Warm-Up', + 'High Intensity', + 'Low Intensity', + 'High Intensity', + 'Low Intensity', + 'High Intensity', + 'Low Intensity', + 'High Intensity', + 'Cool-down' + ]; + final Map _phasesDuration = { + 'Warm-Up': const Duration(seconds: 5), + 'High Intensity': const Duration(seconds: 4), + 'Low Intensity': const Duration(seconds: 3), + 'Cool-down': const Duration(seconds: 5) + }; + int _workoutPhaseIndex = 0; + + String get currentPhase => _workoutPhases[_workoutPhaseIndex]; + Duration get currentPhaseDuration => + _phasesDuration[currentPhase] ?? const Duration(seconds: 0); + + void nextPhase() { + _workoutPhaseIndex < _workoutPhases.length + ? _workoutPhaseIndex += 1 + : _workoutPhaseIndex = 0; + //notifyListeners(); + } +} diff --git a/lib/widgets/workout_timer_widget.dart b/lib/widgets/workout_timer_widget.dart new file mode 100644 index 0000000..1ba501c --- /dev/null +++ b/lib/widgets/workout_timer_widget.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/workout_provider.dart'; +import 'package:smoke_cess_app/widgets/timer_widget.dart'; + +import '../providers/timer_provider.dart'; + +class WorkoutTimerWidget extends StatelessWidget { + const WorkoutTimerWidget({super.key}); + + @override + Widget build(BuildContext context) { + TimerProvider timerProvider = context.watch(); + WorkoutProvider workoutProvider = context.watch(); + + if (timerProvider.elapsedSeconds == + workoutProvider.currentPhaseDuration.inSeconds) { + print('Timer abgelaufen'); + workoutProvider.nextPhase(); + timerProvider.startTimer(workoutProvider.currentPhaseDuration); + } + + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(workoutProvider.currentPhase), + TimerWidget(duration: workoutProvider.currentPhaseDuration) + ], + ); + } +}