Fixed DropDown Bug

main
Kai Mannweiler 2023-03-03 12:51:25 +01:00
parent 36ef18a4f7
commit 606e8c3f19
2 changed files with 3 additions and 8 deletions

View File

@ -11,22 +11,16 @@ class InputProvider extends ChangeNotifier {
'wokeUpAt': const TimeOfDay(hour: 8, minute: 0), 'wokeUpAt': const TimeOfDay(hour: 8, minute: 0),
'sleptAt': const TimeOfDay(hour: 22, minute: 0), 'sleptAt': const TimeOfDay(hour: 22, minute: 0),
}; };
String _relapseCategory = ''; String relapseCategory = '';
double get sliderValue => _sliderValue; double get sliderValue => _sliderValue;
TextEditingController get textController => _textController; TextEditingController get textController => _textController;
String get relapseCategory => _relapseCategory;
set sliderValue(double newValue) { set sliderValue(double newValue) {
_sliderValue = newValue; _sliderValue = newValue;
notifyListeners(); notifyListeners();
} }
set relapseCategory(String newValue) {
_relapseCategory = newValue;
notifyListeners();
}
TimeOfDay getTimeEntry(String key) { TimeOfDay getTimeEntry(String key) {
return _times[key] ?? const TimeOfDay(hour: 12, minute: 0); return _times[key] ?? const TimeOfDay(hour: 12, minute: 0);
} }
@ -53,7 +47,7 @@ class InputProvider extends ChangeNotifier {
Future<int> saveRelapse() { Future<int> saveRelapse() {
Relapse relapse = Relapse relapse =
Relapse(_relapseCategory, _textController.text, DateTime.now()); Relapse(relapseCategory, _textController.text, DateTime.now());
_resetFields(); _resetFields();
return globals.databaseService.addRelapse(relapse); return globals.databaseService.addRelapse(relapse);
} }

View File

@ -9,6 +9,7 @@ class DropDown extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var inputModel = context.watch<InputProvider>(); var inputModel = context.watch<InputProvider>();
inputModel.relapseCategory = _items.isNotEmpty ? _items[0] : '';
return DropdownButtonFormField<String>( return DropdownButtonFormField<String>(
value: _items.isEmpty ? null : _items[0], value: _items.isEmpty ? null : _items[0],
icon: const Icon(Icons.arrow_downward), icon: const Icon(Icons.arrow_downward),