cpd_2022_zi/lib/providers/input_provider.dart

40 lines
996 B
Dart
Raw Normal View History

2023-02-26 14:59:37 +01:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:smoke_cess_app/models/mood.dart';
import '../globals.dart' as globals;
2023-02-26 14:59:37 +01:00
class InputProvider extends ChangeNotifier {
double _sliderValue = 50;
final TextEditingController _textController = TextEditingController(text: '');
final Map<String, TimeOfDay> _times = {};
2023-02-26 14:59:37 +01:00
double get sliderValue => _sliderValue;
TextEditingController get textController => _textController;
2023-02-26 14:59:37 +01:00
set sliderValue(double newValue) {
_sliderValue = newValue;
notifyListeners();
}
TimeOfDay? getTimeEntry(String key) {
return _times[key];
}
void setTime(String key, TimeOfDay time) {
_times[key] = time;
}
void _resetFields() {
_sliderValue = 50;
_textController.text = '';
notifyListeners();
}
void saveMood() {
Mood mood =
Mood(_sliderValue.toInt(), _textController.text, DateTime.now());
globals.databaseService.addMood(mood);
_resetFields();
}
2023-02-26 14:59:37 +01:00
}