Merged with latest changes

This commit is contained in:
Abdullah Alassaf
2024-11-24 01:14:26 +03:00
16 changed files with 871 additions and 710 deletions

View File

@ -19,9 +19,9 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
on<AddToThenContainer>(_onAddToThenContainer);
on<LoadScenes>(_onLoadScenes);
on<LoadAutomation>(_onLoadAutomation);
on<AddFunctionToRoutine>(_onAddFunction);
on<RemoveFunction>(_onRemoveFunction);
on<ClearFunctions>(_onClearFunctions);
on<AddFunctionToRoutine>(_onAddFunctionsToRoutine);
// on<RemoveFunction>(_onRemoveFunction);
// on<ClearFunctions>(_onClearFunctions);
}
void _onAddToIfContainer(AddToIfContainer event, Emitter<RoutineState> emit) {
@ -39,23 +39,32 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
// }
}
void _onAddFunction(AddFunctionToRoutine event, Emitter<RoutineState> emit) {
final functions = List<DeviceFunctionData>.from(state.selectedFunctions);
functions.add(event.function);
debugPrint("******" + functions.toString());
emit(state.copyWith(selectedFunctions: functions));
void _onAddFunctionsToRoutine(AddFunctionToRoutine event, Emitter<RoutineState> emit) {
debugPrint(event.uniqueCustomId.toString());
debugPrint(event.functions.toString());
final currentSelectedFunctions =
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
if (currentSelectedFunctions.containsKey(event.uniqueCustomId)) {
currentSelectedFunctions[event.uniqueCustomId]!.addAll(event.functions);
} else {
currentSelectedFunctions[event.uniqueCustomId] = event.functions;
}
emit(state.copyWith(selectedFunctions: currentSelectedFunctions));
}
void _onRemoveFunction(RemoveFunction event, Emitter<RoutineState> emit) {
final functions = List<DeviceFunctionData>.from(state.selectedFunctions)
..removeWhere(
(f) => f.functionCode == event.function.functionCode && f.value == event.function.value);
emit(state.copyWith(selectedFunctions: functions));
}
// void _onRemoveFunction(RemoveFunction event, Emitter<RoutineState> emit) {
// final functions = List<DeviceFunctionData>.from(state.selectedFunctions)
// ..removeWhere((f) =>
// f.functionCode == event.function.functionCode &&
// f.value == event.function.value);
// emit(state.copyWith(selectedFunctions: functions));
// }
void _onClearFunctions(ClearFunctions event, Emitter<RoutineState> emit) {
emit(state.copyWith(selectedFunctions: []));
}
// void _onClearFunctions(ClearFunctions event, Emitter<RoutineState> emit) {
// emit(state.copyWith(selectedFunctions: []));
// }
// bool _isDuplicate(
// List<Map<String, dynamic>> items, Map<String, dynamic> newItem) {