2023-02-26 14:59:37 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2023-02-26 16:17:57 +01:00
|
|
|
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;
|
2023-02-26 16:17:57 +01:00
|
|
|
final TextEditingController _textController = TextEditingController(text: '');
|
|
|
|
final Map<String, TimeOfDay> _times = {};
|
2023-02-26 14:59:37 +01:00
|
|
|
|
|
|
|
double get sliderValue => _sliderValue;
|
2023-02-26 16:17:57 +01:00
|
|
|
TextEditingController get textController => _textController;
|
2023-02-26 14:59:37 +01:00
|
|
|
|
|
|
|
set sliderValue(double newValue) {
|
|
|
|
_sliderValue = newValue;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
2023-02-26 16:17:57 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|