[preset] GO
This commit is contained in:
parent
e9b2c280d4
commit
2d1a08ac1a
1 changed files with 6 additions and 3 deletions
|
@ -19,6 +19,7 @@ class _AddMealScreen extends State<AddMealScreen> {
|
||||||
final presetNameController = TextEditingController();
|
final presetNameController = TextEditingController();
|
||||||
bool nameChanged = false;
|
bool nameChanged = false;
|
||||||
List<Preset> presets = [];
|
List<Preset> presets = [];
|
||||||
|
Preset? selectedPreset;
|
||||||
|
|
||||||
Future<void> _getPresets() async {
|
Future<void> _getPresets() async {
|
||||||
var presetsMap =
|
var presetsMap =
|
||||||
|
@ -28,6 +29,7 @@ class _AddMealScreen extends State<AddMealScreen> {
|
||||||
presets = (presetsMap['presets'] as List<dynamic>)
|
presets = (presetsMap['presets'] as List<dynamic>)
|
||||||
.map((e) => Preset.fromJson(e as Map<String, dynamic>))
|
.map((e) => Preset.fromJson(e as Map<String, dynamic>))
|
||||||
.toList();
|
.toList();
|
||||||
|
selectedPreset = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,16 +106,16 @@ class _AddMealScreen extends State<AddMealScreen> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _addMealFromPreset() async {
|
Future<void> _addMealFromPreset() async {
|
||||||
if (presets.length != 1) {
|
if (selectedPreset == null) {
|
||||||
_addMeal();
|
_addMeal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await widget.apiClient.addMealFromPreset(
|
await widget.apiClient.addMealFromPreset(
|
||||||
name: nameChanged ? nameController.text : presets[0].name,
|
name: nameChanged ? nameController.text : selectedPreset!.name,
|
||||||
diaryId: widget.diary.id,
|
diaryId: widget.diary.id,
|
||||||
order: widget.diary.meals.length,
|
order: widget.diary.meals.length,
|
||||||
presetId: presets[0].id,
|
presetId: selectedPreset!.id,
|
||||||
);
|
);
|
||||||
popMeDaddy();
|
popMeDaddy();
|
||||||
}
|
}
|
||||||
|
@ -152,6 +154,7 @@ class _AddMealScreen extends State<AddMealScreen> {
|
||||||
setState(() {
|
setState(() {
|
||||||
presets = [preset];
|
presets = [preset];
|
||||||
presetNameController.text = preset.name;
|
presetNameController.text = preset.name;
|
||||||
|
selectedPreset = preset;
|
||||||
});
|
});
|
||||||
_addMealFromPreset();
|
_addMealFromPreset();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue