diff --git a/assets/icons/duplicate.svg b/assets/icons/duplicate.svg
new file mode 100644
index 00000000..1faa1bab
--- /dev/null
+++ b/assets/icons/duplicate.svg
@@ -0,0 +1,16 @@
+
diff --git a/assets/icons/space_delete.svg b/assets/icons/space_delete.svg
new file mode 100644
index 00000000..90c3413e
--- /dev/null
+++ b/assets/icons/space_delete.svg
@@ -0,0 +1,9 @@
+
diff --git a/lib/pages/spaces_management/add_device_type/bloc/add_device_model_bloc.dart b/lib/pages/spaces_management/add_device_type/bloc/add_device_model_bloc.dart
index 10f3327e..e84851c5 100644
--- a/lib/pages/spaces_management/add_device_type/bloc/add_device_model_bloc.dart
+++ b/lib/pages/spaces_management/add_device_type/bloc/add_device_model_bloc.dart
@@ -1,38 +1,74 @@
import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:syncrow_web/pages/spaces_management/add_device_type/bloc/add_device_state.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
import 'package:syncrow_web/pages/spaces_management/add_device_type/bloc/add_device_type_model_event.dart';
-class AddDeviceTypeBloc
- extends Bloc> {
- AddDeviceTypeBloc(List initialProducts)
- : super(initialProducts) {
+class AddDeviceTypeBloc extends Bloc {
+ AddDeviceTypeBloc() : super(AddDeviceInitial()) {
+ on(_onInitializeTagModels);
on(_onUpdateProductCount);
}
- void _onUpdateProductCount(
- UpdateProductCountEvent event, Emitter> emit) {
- final existingProduct = state.firstWhere(
- (p) => p.productId == event.productId,
- orElse: () => SelectedProduct(productId: event.productId, count: 0,productName: event.productName,product: event.product ),
- );
+ void _onInitializeTagModels(
+ InitializeDevice event, Emitter emit) {
+ emit(AddDeviceLoaded(
+ selectedProducts: event.addedProducts,
+ initialTag: event.initialTags,
+ ));
+ }
- if (event.count > 0) {
- if (!state.contains(existingProduct)) {
- emit([
- ...state,
- SelectedProduct(productId: event.productId, count: event.count, productName: event.productName, product: event.product)
- ]);
+ void _onUpdateProductCount(
+ UpdateProductCountEvent event, Emitter emit) {
+ final currentState = state;
+
+ if (currentState is AddDeviceLoaded) {
+ final existingProduct = currentState.selectedProducts.firstWhere(
+ (p) => p.productId == event.productId,
+ orElse: () => SelectedProduct(
+ productId: event.productId,
+ count: 0,
+ productName: event.productName,
+ product: event.product,
+ ),
+ );
+
+ List updatedProducts;
+
+ if (event.count > 0) {
+ if (!currentState.selectedProducts.contains(existingProduct)) {
+ updatedProducts = [
+ ...currentState.selectedProducts,
+ SelectedProduct(
+ productId: event.productId,
+ count: event.count,
+ productName: event.productName,
+ product: event.product,
+ ),
+ ];
+ } else {
+ updatedProducts = currentState.selectedProducts.map((p) {
+ if (p.productId == event.productId) {
+ return SelectedProduct(
+ productId: p.productId,
+ count: event.count,
+ productName: p.productName,
+ product: p.product,
+ );
+ }
+ return p;
+ }).toList();
+ }
} else {
- final updatedList = state.map((p) {
- if (p.productId == event.productId) {
- return SelectedProduct(productId: p.productId, count: event.count, productName: p.productName,product: p.product);
- }
- return p;
- }).toList();
- emit(updatedList);
+ // Remove the product if the count is 0
+ updatedProducts = currentState.selectedProducts
+ .where((p) => p.productId != event.productId)
+ .toList();
}
- } else {
- emit(state.where((p) => p.productId != event.productId).toList());
+
+ // Emit the updated state
+ emit(AddDeviceLoaded(
+ selectedProducts: updatedProducts,
+ initialTag: currentState.initialTag));
}
}
}
diff --git a/lib/pages/spaces_management/add_device_type/bloc/add_device_state.dart b/lib/pages/spaces_management/add_device_type/bloc/add_device_state.dart
new file mode 100644
index 00000000..e1fa2593
--- /dev/null
+++ b/lib/pages/spaces_management/add_device_type/bloc/add_device_state.dart
@@ -0,0 +1,36 @@
+import 'package:equatable/equatable.dart';
+import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
+import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
+
+abstract class AddDeviceState extends Equatable {
+ const AddDeviceState();
+
+ @override
+ List