playing music and iterating throug workout
parent
ec5f23845d
commit
b01485f27a
|
@ -170,10 +170,12 @@ class _IntervalTimerPageState extends State<IntervalTimerPage> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
TimerProvider timerProvider = TimerProvider();
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(create: (context) => TimerProvider()),
|
||||
ChangeNotifierProvider(create: (context) => WorkoutProvider())
|
||||
ChangeNotifierProvider(create: (context) => timerProvider),
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => WorkoutProvider(timerProvider))
|
||||
],
|
||||
child: WorkoutTimerWidget(),
|
||||
);
|
||||
|
|
|
@ -11,7 +11,6 @@ class TimerProvider extends ChangeNotifier {
|
|||
started = true;
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), ((timer) {
|
||||
if (timer.tick >= duration.inSeconds) {
|
||||
print(elapsedSeconds);
|
||||
timer.cancel();
|
||||
started = false;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:smoke_cess_app/providers/timer_provider.dart';
|
||||
|
||||
class WorkoutProvider extends ChangeNotifier {
|
||||
TimerProvider timerProvider;
|
||||
|
||||
final AudioPlayer _audioPlayer = AudioPlayer();
|
||||
|
||||
WorkoutProvider(this.timerProvider);
|
||||
|
||||
final List<String> _workoutPhases = [
|
||||
'Warm-Up',
|
||||
'High Intensity',
|
||||
|
@ -18,6 +28,12 @@ class WorkoutProvider extends ChangeNotifier {
|
|||
'Low Intensity': const Duration(seconds: 3),
|
||||
'Cool-down': const Duration(seconds: 5)
|
||||
};
|
||||
final Map<String, Source> _phaseSongSources = {
|
||||
'Warm-Up': AssetSource('warmUp.mp3'),
|
||||
'High Intensity': AssetSource('workout.mp3'),
|
||||
'Low Intensity': AssetSource('workout.mp3'),
|
||||
'Cool-down': AssetSource('cool_down.mp3')
|
||||
};
|
||||
int _workoutPhaseIndex = 0;
|
||||
|
||||
String get currentPhase => _workoutPhases[_workoutPhaseIndex];
|
||||
|
@ -25,9 +41,11 @@ class WorkoutProvider extends ChangeNotifier {
|
|||
_phasesDuration[currentPhase] ?? const Duration(seconds: 0);
|
||||
|
||||
void nextPhase() {
|
||||
_workoutPhaseIndex < _workoutPhases.length
|
||||
? _workoutPhaseIndex += 1
|
||||
: _workoutPhaseIndex = 0;
|
||||
//notifyListeners();
|
||||
_audioPlayer.stop();
|
||||
if (_workoutPhaseIndex < _workoutPhases.length - 1) {
|
||||
_workoutPhaseIndex += 1;
|
||||
_audioPlayer.play(_phaseSongSources[currentPhase]!);
|
||||
timerProvider.startTimer(currentPhaseDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:smoke_cess_app/providers/workout_provider.dart';
|
||||
|
@ -15,9 +17,7 @@ class WorkoutTimerWidget extends StatelessWidget {
|
|||
|
||||
if (timerProvider.elapsedSeconds ==
|
||||
workoutProvider.currentPhaseDuration.inSeconds) {
|
||||
print('Timer abgelaufen');
|
||||
workoutProvider.nextPhase();
|
||||
timerProvider.startTimer(workoutProvider.currentPhaseDuration);
|
||||
Timer(const Duration(milliseconds: 1), () => workoutProvider.nextPhase());
|
||||
}
|
||||
|
||||
return Column(
|
||||
|
|
Loading…
Reference in New Issue