Enums instead of Strings
parent
be24c4d781
commit
4e6f5e2d8c
|
@ -4,12 +4,17 @@ import 'package:smoke_cess_app/models/relapse.dart';
|
|||
import 'package:smoke_cess_app/models/sleep.dart';
|
||||
import '../globals.dart' as globals;
|
||||
|
||||
enum SleepTimes {
|
||||
wokeUpAt,
|
||||
sleptAt,
|
||||
}
|
||||
|
||||
class InputProvider extends ChangeNotifier {
|
||||
double _sliderValue = 50;
|
||||
final TextEditingController _textController = TextEditingController(text: '');
|
||||
final Map<String, TimeOfDay> _times = {
|
||||
'wokeUpAt': const TimeOfDay(hour: 8, minute: 0),
|
||||
'sleptAt': const TimeOfDay(hour: 22, minute: 0),
|
||||
final Map<SleepTimes, TimeOfDay> _times = {
|
||||
SleepTimes.wokeUpAt: const TimeOfDay(hour: 8, minute: 0),
|
||||
SleepTimes.sleptAt: const TimeOfDay(hour: 22, minute: 0),
|
||||
};
|
||||
String relapseCategory = '';
|
||||
|
||||
|
@ -21,11 +26,11 @@ class InputProvider extends ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
TimeOfDay getTimeEntry(String key) {
|
||||
TimeOfDay getTimeEntry(SleepTimes key) {
|
||||
return _times[key] ?? const TimeOfDay(hour: 12, minute: 0);
|
||||
}
|
||||
|
||||
void setTime(String key, TimeOfDay time) {
|
||||
void setTime(SleepTimes key, TimeOfDay time) {
|
||||
_times[key] = time;
|
||||
notifyListeners();
|
||||
}
|
||||
|
@ -33,8 +38,8 @@ class InputProvider extends ChangeNotifier {
|
|||
void _resetFields() {
|
||||
_sliderValue = 50;
|
||||
_textController.text = '';
|
||||
setTime('wokeUpAt', const TimeOfDay(hour: 8, minute: 0));
|
||||
setTime('sleptAt', const TimeOfDay(hour: 22, minute: 0));
|
||||
setTime(SleepTimes.wokeUpAt, const TimeOfDay(hour: 8, minute: 0));
|
||||
setTime(SleepTimes.sleptAt, const TimeOfDay(hour: 22, minute: 0));
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
@ -52,7 +57,7 @@ class InputProvider extends ChangeNotifier {
|
|||
return globals.databaseService.addRelapse(relapse);
|
||||
}
|
||||
|
||||
Future<int> saveSleep(String wokeUpKey, String sleptKey) {
|
||||
Future<int> saveSleep(SleepTimes wokeUpKey, SleepTimes sleptKey) {
|
||||
Sleep sleep = Sleep(_sliderValue.toInt(), _textController.text,
|
||||
DateTime.now(), getTimeEntry(sleptKey), getTimeEntry(wokeUpKey));
|
||||
_resetFields();
|
||||
|
|
|
@ -5,6 +5,13 @@ import 'package:smoke_cess_app/providers/audio_provider.dart';
|
|||
import 'package:smoke_cess_app/providers/timer_provider.dart';
|
||||
import '../globals.dart' as globals;
|
||||
|
||||
enum WorkoutPhases {
|
||||
warmUp,
|
||||
highIntensity,
|
||||
lowIntensity,
|
||||
coolDown,
|
||||
}
|
||||
|
||||
class WorkoutProvider extends ChangeNotifier {
|
||||
final TimerProvider timerProvider;
|
||||
final AudioProvider audioProvider;
|
||||
|
@ -15,21 +22,21 @@ class WorkoutProvider extends ChangeNotifier {
|
|||
int motivationAfter = 50;
|
||||
|
||||
int _workoutPhaseIndex = 0;
|
||||
final List<String> _workoutPhases = [
|
||||
'Warm-Up',
|
||||
'High Intensity',
|
||||
'Low Intensity',
|
||||
'High Intensity',
|
||||
'Low Intensity',
|
||||
'High Intensity',
|
||||
'Low Intensity',
|
||||
'High Intensity',
|
||||
'Cool-down'
|
||||
final List<WorkoutPhases> _workoutPhases = [
|
||||
WorkoutPhases.warmUp,
|
||||
WorkoutPhases.highIntensity,
|
||||
WorkoutPhases.lowIntensity,
|
||||
WorkoutPhases.highIntensity,
|
||||
WorkoutPhases.lowIntensity,
|
||||
WorkoutPhases.highIntensity,
|
||||
WorkoutPhases.lowIntensity,
|
||||
WorkoutPhases.highIntensity,
|
||||
WorkoutPhases.coolDown,
|
||||
];
|
||||
|
||||
WorkoutProvider(this.timerProvider, this.audioProvider);
|
||||
|
||||
String get currentPhase => _workoutPhases[_workoutPhaseIndex];
|
||||
WorkoutPhases get currentPhase => _workoutPhases[_workoutPhaseIndex];
|
||||
Duration get currentPhaseDuration =>
|
||||
_workoutPhaseSettings[currentPhase]!['duration'];
|
||||
bool get isPhaseComplete =>
|
||||
|
@ -37,6 +44,7 @@ class WorkoutProvider extends ChangeNotifier {
|
|||
Color get currentPhaseColor => _workoutPhaseSettings[currentPhase]!['color'];
|
||||
AssetSource get currentPhaseSource =>
|
||||
_workoutPhaseSettings[currentPhase]!['source'];
|
||||
String get currentPhaseTitle => _workoutPhaseSettings[currentPhase]!['title'];
|
||||
|
||||
void nextPhase() {
|
||||
if (_workoutPhaseIndex < _workoutPhases.length - 1) {
|
||||
|
@ -89,23 +97,27 @@ class WorkoutProvider extends ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
Map<String, Map<String, dynamic>> _workoutPhaseSettings = {
|
||||
'Warm-Up': {
|
||||
Map<WorkoutPhases, Map<String, dynamic>> _workoutPhaseSettings = {
|
||||
WorkoutPhases.warmUp: {
|
||||
'title': 'Warm Up',
|
||||
'duration': const Duration(seconds: 5),
|
||||
'source': AssetSource('warmUp.mp3'),
|
||||
'color': Colors.green
|
||||
},
|
||||
'High Intensity': {
|
||||
WorkoutPhases.highIntensity: {
|
||||
'title': 'High Intensity',
|
||||
'duration': const Duration(seconds: 4),
|
||||
'source': AssetSource('workout.mp3'),
|
||||
'color': Colors.red
|
||||
},
|
||||
'Low Intensity': {
|
||||
WorkoutPhases.lowIntensity: {
|
||||
'title': 'Low Intensity',
|
||||
'duration': const Duration(seconds: 3),
|
||||
'source': AssetSource('workout.mp3'),
|
||||
'color': Colors.orange
|
||||
},
|
||||
'Cool-down': {
|
||||
WorkoutPhases.coolDown: {
|
||||
'title': 'Cool Down',
|
||||
'duration': const Duration(seconds: 5),
|
||||
'source': AssetSource('cool_down.mp3'),
|
||||
'color': Colors.blue
|
||||
|
|
|
@ -17,20 +17,18 @@ class SleepForm extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
InputProvider inputModel = context.watch<InputProvider>();
|
||||
TasksProvider tasksModel = context.watch<TasksProvider>();
|
||||
String wokeUpKey = 'wokeUpAt';
|
||||
String sleptKey = 'sleptAt';
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
ElevatedCard(
|
||||
const ElevatedCard(
|
||||
title: 'Einschlafzeit',
|
||||
child: TimePicker(sleptKey),
|
||||
child: TimePicker(SleepTimes.sleptAt),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedCard(
|
||||
const ElevatedCard(
|
||||
title: 'Aufwachzeit',
|
||||
child: TimePicker(wokeUpKey),
|
||||
child: TimePicker(SleepTimes.wokeUpAt),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const ElevatedCard(
|
||||
|
@ -46,7 +44,8 @@ class SleepForm extends StatelessWidget {
|
|||
height: 80,
|
||||
),
|
||||
SubmitFormButton(
|
||||
submitCallback: () => inputModel.saveSleep(wokeUpKey, sleptKey),
|
||||
submitCallback: () =>
|
||||
inputModel.saveSleep(SleepTimes.wokeUpAt, SleepTimes.sleptAt),
|
||||
updateTasks: () => tasksModel.setTaskDone(Pages.mood),
|
||||
)
|
||||
],
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'package:smoke_cess_app/providers/input_provider.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
class TimePicker extends StatelessWidget {
|
||||
final String keyMap;
|
||||
final SleepTimes keyMap;
|
||||
|
||||
const TimePicker(this.keyMap, {super.key});
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ class WorkoutTimerWidget extends StatelessWidget {
|
|||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(workoutProvider.currentPhase),
|
||||
Text(workoutProvider.currentPhaseTitle),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue