fixed editing

This commit is contained in:
Vadim 2025-09-04 20:07:54 +02:00
parent 3b9d93b9a8
commit 2fcda9bf24

View file

@ -60,10 +60,22 @@ sealed class IEquipmentProfileEditBloc<T extends IEquipmentProfile>
Future<void> _onSave(EquipmentProfileSaveEvent<T> _, Emitter emit) async { Future<void> _onSave(EquipmentProfileSaveEvent<T> _, Emitter emit) async {
emit(state.copyWith(isLoading: true)); emit(state.copyWith(isLoading: true));
final profileId = isEdit ? originalEquipmentProfile.id : const Uuid().v1(); if (isEdit) {
final newProfile = await createProfile(profileId); final newProfile = await createProfile(originalEquipmentProfile.id);
assert(newProfile.id == profileId, 'The new profile id must be the same as the original profile id'); assert(
await profilesProvider.addProfile(newProfile); 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)); emit(state.copyWith(isLoading: false));
} }