52 lines
1.5 KiB
Dart
52 lines
1.5 KiB
Dart
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',
|
|
'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)
|
|
};
|
|
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];
|
|
Duration get currentPhaseDuration =>
|
|
_phasesDuration[currentPhase] ?? const Duration(seconds: 0);
|
|
|
|
void nextPhase() {
|
|
_audioPlayer.stop();
|
|
if (_workoutPhaseIndex < _workoutPhases.length - 1) {
|
|
_workoutPhaseIndex += 1;
|
|
_audioPlayer.play(_phaseSongSources[currentPhase]!);
|
|
timerProvider.startTimer(currentPhaseDuration);
|
|
}
|
|
}
|
|
}
|