fixes unique id for card drag

This commit is contained in:
ashrafzarkanisala
2024-11-24 01:10:31 +03:00
parent 590a41ff83
commit 5e94de5d78
17 changed files with 905 additions and 712 deletions
@@ -16,9 +16,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) {
@@ -38,24 +38,33 @@ 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) {
@@ -44,10 +44,11 @@ class LoadAutomation extends RoutineEvent {
}
class AddFunctionToRoutine extends RoutineEvent {
final DeviceFunctionData function;
const AddFunctionToRoutine(this.function);
final List<DeviceFunctionData> functions;
final String uniqueCustomId;
const AddFunctionToRoutine(this.functions, this.uniqueCustomId);
@override
List<Object> get props => [function];
List<Object> get props => [functions];
}
class RemoveFunction extends RoutineEvent {
@@ -6,7 +6,7 @@ class RoutineState extends Equatable {
final List<Map<String, String>> availableCards;
final List<ScenesModel> scenes;
final List<ScenesModel> automations;
final List<DeviceFunctionData> selectedFunctions;
final Map<String, List<DeviceFunctionData>> selectedFunctions;
final bool isLoading;
final String? errorMessage;
@@ -16,7 +16,7 @@ class RoutineState extends Equatable {
this.availableCards = const [],
this.scenes = const [],
this.automations = const [],
this.selectedFunctions = const [],
this.selectedFunctions = const {},
this.isLoading = false,
this.errorMessage,
});
@@ -26,7 +26,7 @@ class RoutineState extends Equatable {
List<Map<String, dynamic>>? thenItems,
List<ScenesModel>? scenes,
List<ScenesModel>? automations,
List<DeviceFunctionData>? selectedFunctions,
Map<String, List<DeviceFunctionData>>? selectedFunctions,
bool? isLoading,
String? errorMessage,
}) {