From 606e8c3f192ae7acf60631647e5635788f463871 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Fri, 3 Mar 2023 12:51:25 +0100 Subject: [PATCH] Fixed DropDown Bug --- lib/providers/input_provider.dart | 10 ++-------- lib/widgets/drop_down.dart | 1 + 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/providers/input_provider.dart b/lib/providers/input_provider.dart index a61514f..3bd473f 100644 --- a/lib/providers/input_provider.dart +++ b/lib/providers/input_provider.dart @@ -11,22 +11,16 @@ class InputProvider extends ChangeNotifier { 'wokeUpAt': const TimeOfDay(hour: 8, minute: 0), 'sleptAt': const TimeOfDay(hour: 22, minute: 0), }; - String _relapseCategory = ''; + String relapseCategory = ''; double get sliderValue => _sliderValue; TextEditingController get textController => _textController; - String get relapseCategory => _relapseCategory; set sliderValue(double newValue) { _sliderValue = newValue; notifyListeners(); } - set relapseCategory(String newValue) { - _relapseCategory = newValue; - notifyListeners(); - } - TimeOfDay getTimeEntry(String key) { return _times[key] ?? const TimeOfDay(hour: 12, minute: 0); } @@ -53,7 +47,7 @@ class InputProvider extends ChangeNotifier { Future saveRelapse() { Relapse relapse = - Relapse(_relapseCategory, _textController.text, DateTime.now()); + Relapse(relapseCategory, _textController.text, DateTime.now()); _resetFields(); return globals.databaseService.addRelapse(relapse); } diff --git a/lib/widgets/drop_down.dart b/lib/widgets/drop_down.dart index 5f06d89..ee704cf 100644 --- a/lib/widgets/drop_down.dart +++ b/lib/widgets/drop_down.dart @@ -9,6 +9,7 @@ class DropDown extends StatelessWidget { @override Widget build(BuildContext context) { var inputModel = context.watch(); + inputModel.relapseCategory = _items.isNotEmpty ? _items[0] : ''; return DropdownButtonFormField( value: _items.isEmpty ? null : _items[0], icon: const Icon(Icons.arrow_downward),