From 2fcda9bf2489c6bfab1be43fa5f1ab3bfa922aff Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Thu, 4 Sep 2025 20:07:54 +0200 Subject: [PATCH] fixed editing --- .../bloc_equipment_profile_edit.dart | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/screens/equipment_profile_edit/bloc_equipment_profile_edit.dart b/lib/screens/equipment_profile_edit/bloc_equipment_profile_edit.dart index 1db00c3..6c1aebb 100644 --- a/lib/screens/equipment_profile_edit/bloc_equipment_profile_edit.dart +++ b/lib/screens/equipment_profile_edit/bloc_equipment_profile_edit.dart @@ -60,10 +60,22 @@ sealed class IEquipmentProfileEditBloc Future _onSave(EquipmentProfileSaveEvent _, Emitter emit) async { emit(state.copyWith(isLoading: true)); - final profileId = isEdit ? originalEquipmentProfile.id : const Uuid().v1(); - final newProfile = await createProfile(profileId); - assert(newProfile.id == profileId, 'The new profile id must be the same as the original profile id'); - await profilesProvider.addProfile(newProfile); + if (isEdit) { + final newProfile = await createProfile(originalEquipmentProfile.id); + assert( + newProfile.id == originalEquipmentProfile.id, + 'The edited profile id must be the same as the original profile id', + ); + await profilesProvider.updateProfile(newProfile); + } else { + final newId = const Uuid().v1(); + final newProfile = await createProfile(newId); + assert( + newProfile.id == newId, + 'A profile to be added must have a unique id.', + ); + await profilesProvider.addProfile(newProfile); + } emit(state.copyWith(isLoading: false)); }