From 2d1a08ac1a1c0788ef83ade97ab427a14e539fa5 Mon Sep 17 00:00:00 2001 From: doman Date: Fri, 27 Oct 2023 17:44:03 +0200 Subject: [PATCH] [preset] GO --- lib/screens/add_meal.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/screens/add_meal.dart b/lib/screens/add_meal.dart index d073045..0dcb8d1 100644 --- a/lib/screens/add_meal.dart +++ b/lib/screens/add_meal.dart @@ -19,6 +19,7 @@ class _AddMealScreen extends State { final presetNameController = TextEditingController(); bool nameChanged = false; List presets = []; + Preset? selectedPreset; Future _getPresets() async { var presetsMap = @@ -28,6 +29,7 @@ class _AddMealScreen extends State { presets = (presetsMap['presets'] as List) .map((e) => Preset.fromJson(e as Map)) .toList(); + selectedPreset = null; }); } @@ -104,16 +106,16 @@ class _AddMealScreen extends State { } Future _addMealFromPreset() async { - if (presets.length != 1) { + if (selectedPreset == null) { _addMeal(); return; } await widget.apiClient.addMealFromPreset( - name: nameChanged ? nameController.text : presets[0].name, + name: nameChanged ? nameController.text : selectedPreset!.name, diaryId: widget.diary.id, order: widget.diary.meals.length, - presetId: presets[0].id, + presetId: selectedPreset!.id, ); popMeDaddy(); } @@ -152,6 +154,7 @@ class _AddMealScreen extends State { setState(() { presets = [preset]; presetNameController.text = preset.name; + selectedPreset = preset; }); _addMealFromPreset(); },