Implemented update card functionlity

This commit is contained in:
Abdullah Alassaf
2024-11-26 00:43:35 +03:00
parent bbe00c0372
commit c84cfd75e4
4 changed files with 82 additions and 36 deletions

View File

@ -44,8 +44,19 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
}
void _onAddToThenContainer(AddToThenContainer event, Emitter<RoutineState> emit) {
final updatedThenItems = List<Map<String, dynamic>>.from(state.thenItems)..add(event.item);
emit(state.copyWith(thenItems: updatedThenItems));
final currentItems = List<Map<String, dynamic>>.from(state.thenItems);
// Find the index of the item in teh current itemsList
int index =
currentItems.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
// Replace the map if the index is valid
if (index != -1) {
currentItems[index] = event.item;
} else {
currentItems.add(event.item);
}
emit(state.copyWith(thenItems: currentItems));
}
void _onAddFunctionsToRoutine(AddFunctionToRoutine event, Emitter<RoutineState> emit) {