finished ac devices

This commit is contained in:
ashrafzarkanisala
2024-11-23 21:51:20 +03:00
parent 5e91d7c03a
commit 7dccfb5a76
25 changed files with 810 additions and 770 deletions
@@ -1,5 +1,6 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
import 'package:syncrow_web/pages/routiens/models/routine_model.dart';
import 'package:syncrow_web/services/routines_api.dart';
@@ -21,32 +22,33 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
}
void _onAddToIfContainer(AddToIfContainer event, Emitter<RoutineState> emit) {
if (!_isDuplicate(state.ifItems, event.item)) {
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems)
..add(event.item);
emit(state.copyWith(ifItems: updatedIfItems));
}
// if (!_isDuplicate(state.ifItems, event.item)) {
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems)
..add(event.item);
emit(state.copyWith(ifItems: updatedIfItems));
// }
}
void _onAddToThenContainer(
AddToThenContainer event, Emitter<RoutineState> emit) {
if (!_isDuplicate(state.thenItems, event.item)) {
final updatedThenItems = List<Map<String, dynamic>>.from(state.thenItems)
..add(event.item);
emit(state.copyWith(thenItems: updatedThenItems));
}
// if (!_isDuplicate(state.thenItems, event.item)) {
final updatedThenItems = List<Map<String, dynamic>>.from(state.thenItems)
..add(event.item);
emit(state.copyWith(thenItems: updatedThenItems));
// }
}
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 _onRemoveFunction(RemoveFunction event, Emitter<RoutineState> emit) {
final functions = List<DeviceFunctionData>.from(state.selectedFunctions)
..removeWhere((f) =>
f.function == event.function.function &&
f.functionCode == event.function.functionCode &&
f.value == event.function.value);
emit(state.copyWith(selectedFunctions: functions));
}
@@ -55,12 +57,12 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
emit(state.copyWith(selectedFunctions: []));
}
bool _isDuplicate(
List<Map<String, dynamic>> items, Map<String, dynamic> newItem) {
return items.any((item) =>
item['imagePath'] == newItem['imagePath'] &&
item['title'] == newItem['title']);
}
// bool _isDuplicate(
// List<Map<String, dynamic>> items, Map<String, dynamic> newItem) {
// return items.any((item) =>
// item['imagePath'] == newItem['imagePath'] &&
// item['title'] == newItem['title']);
// }
Future<void> _onLoadScenes(
LoadScenes event, Emitter<RoutineState> emit) async {