2023-02-28 13:05:51 +01:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:audioplayers/audioplayers.dart';
|
2023-02-27 01:20:00 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2023-02-28 13:05:51 +01:00
|
|
|
import 'package:smoke_cess_app/providers/timer_provider.dart';
|
2023-02-27 01:20:00 +01:00
|
|
|
|
|
|
|
class WorkoutProvider extends ChangeNotifier {
|
2023-02-28 13:05:51 +01:00
|
|
|
TimerProvider timerProvider;
|
|
|
|
|
|
|
|
final AudioPlayer _audioPlayer = AudioPlayer();
|
|
|
|
|
|
|
|
WorkoutProvider(this.timerProvider);
|
|
|
|
|
2023-02-27 01:20:00 +01:00
|
|
|
final List<String> _workoutPhases = [
|
|
|
|
'Warm-Up',
|
|
|
|
'High Intensity',
|
|
|
|
'Low Intensity',
|
|
|
|
'High Intensity',
|
|
|
|
'Low Intensity',
|
|
|
|
'High Intensity',
|
|
|
|
'Low Intensity',
|
|
|
|
'High Intensity',
|
|
|
|
'Cool-down'
|
|
|
|
];
|
|
|
|
final Map<String, Duration> _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)
|
|
|
|
};
|
2023-02-28 13:05:51 +01:00
|
|
|
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')
|
|
|
|
};
|
2023-02-27 01:20:00 +01:00
|
|
|
int _workoutPhaseIndex = 0;
|
|
|
|
|
|
|
|
String get currentPhase => _workoutPhases[_workoutPhaseIndex];
|
|
|
|
Duration get currentPhaseDuration =>
|
|
|
|
_phasesDuration[currentPhase] ?? const Duration(seconds: 0);
|
|
|
|
|
|
|
|
void nextPhase() {
|
2023-02-28 13:05:51 +01:00
|
|
|
_audioPlayer.stop();
|
|
|
|
if (_workoutPhaseIndex < _workoutPhases.length - 1) {
|
|
|
|
_workoutPhaseIndex += 1;
|
|
|
|
_audioPlayer.play(_phaseSongSources[currentPhase]!);
|
|
|
|
timerProvider.startTimer(currentPhaseDuration);
|
|
|
|
}
|
2023-02-27 01:20:00 +01:00
|
|
|
}
|
|
|
|
}
|