diff --git a/lib/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart b/lib/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart index 1c7ab2d0..acdb75d8 100644 --- a/lib/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart +++ b/lib/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart'; import 'package:syncrow_web/utils/color_manager.dart'; @@ -9,11 +10,13 @@ class AssignTagModelsDialog extends StatefulWidget { final List? subspaces; final List? initialTags; final ValueChanged>? onTagsAssigned; + final List addedProducts; const AssignTagModelsDialog({ Key? key, required this.products, required this.subspaces, + required this.addedProducts, this.initialTags, this.onTagsAssigned, }) : super(key: key); @@ -24,15 +27,17 @@ class AssignTagModelsDialog extends StatefulWidget { class AssignTagModelsDialogState extends State { late List tags; + late List selectedProducts; @override void initState() { super.initState(); - + if (widget.products != null) { print(widget.products); tags = []; } + selectedProducts = widget.addedProducts; } @override @@ -50,19 +55,18 @@ class AssignTagModelsDialogState extends State { DataColumn(label: Text('Tag')), DataColumn(label: Text('Location')), ], - rows: tags.asMap().entries.map((entry) { + rows: selectedProducts.asMap().entries.map((entry) { final index = entry.key + 1; - final tagModel = entry.value; + final selectedProduct = entry.value; return DataRow(cells: [ DataCell(Text(index.toString())), - DataCell(Text(tagModel.product?.name ?? 'Unknown')), + DataCell(Text(selectedProduct.productName ?? 'Unknown')), DataCell( DropdownButton( - value: tagModel.tag, + value: + 'Tag 1', // Static text that matches an item in the list onChanged: (value) { - setState(() { - tagModel.tag = value!; - }); + // Handle value change if needed }, items: List.generate(10, (index) { final tag = 'Tag ${index + 1}'; @@ -72,14 +76,12 @@ class AssignTagModelsDialogState extends State { ), DataCell( DropdownButton( - value: widget.subspaces - ?.firstWhere( - (subspace) => - subspace.subspaceName == 'ssdsdf', - ) - .subspaceName ?? - 'None', - onChanged: (value) {}, + value: widget.subspaces?.isNotEmpty == true + ? widget.subspaces!.first.subspaceName + : null, + onChanged: (value) { + // Handle value changes here + }, items: widget.subspaces! .map((subspace) => DropdownMenuItem( value: subspace.subspaceName, diff --git a/lib/pages/spaces_management/all_spaces/model/selected_product_model.dart b/lib/pages/spaces_management/all_spaces/model/selected_product_model.dart index 9a06698f..31d7f6f8 100644 --- a/lib/pages/spaces_management/all_spaces/model/selected_product_model.dart +++ b/lib/pages/spaces_management/all_spaces/model/selected_product_model.dart @@ -1,13 +1,15 @@ class SelectedProduct { final String productId; int count; + final String productName; - SelectedProduct({required this.productId, required this.count}); + SelectedProduct({required this.productId, required this.count, required this.productName}); Map toJson() { return { 'productId': productId, 'count': count, + 'productName': productName, }; } diff --git a/lib/pages/spaces_management/all_spaces/model/space_model.dart b/lib/pages/spaces_management/all_spaces/model/space_model.dart index df6550f8..7406d919 100644 --- a/lib/pages/spaces_management/all_spaces/model/space_model.dart +++ b/lib/pages/spaces_management/all_spaces/model/space_model.dart @@ -90,6 +90,7 @@ class SpaceModel { return SelectedProduct( productId: product['product']['uuid'], count: product['productCount'], + productName: '', ); }).toList() : [], diff --git a/lib/pages/spaces_management/all_spaces/widgets/add_device_type_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/add_device_type_widget.dart index 40759b58..ed764250 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/add_device_type_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/add_device_type_widget.dart @@ -114,7 +114,7 @@ class _AddDeviceWidgetState extends State { Widget _buildDeviceTypeTile(ProductModel product, Size size) { final selectedProduct = productCounts.firstWhere( (p) => p.productId == product.uuid, - orElse: () => SelectedProduct(productId: product.uuid, count: 0), + orElse: () => SelectedProduct(productId: product.uuid, count: 0, productName: product.catName), ); return SizedBox( @@ -143,7 +143,7 @@ class _AddDeviceWidgetState extends State { if (newCount > 0) { if (!productCounts.contains(selectedProduct)) { productCounts - .add(SelectedProduct(productId: product.uuid, count: newCount)); + .add(SelectedProduct(productId: product.uuid, count: newCount, productName: product.catName)); } else { selectedProduct.count = newCount; } diff --git a/lib/pages/spaces_management/space_model/models/tag_model.dart b/lib/pages/spaces_management/space_model/models/tag_model.dart index a9512107..820b9515 100644 --- a/lib/pages/spaces_management/space_model/models/tag_model.dart +++ b/lib/pages/spaces_management/space_model/models/tag_model.dart @@ -1,19 +1,25 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; +import 'package:uuid/uuid.dart'; class TagModel { String? uuid; String tag; final ProductModel? product; + String internalId; TagModel({ this.uuid, required this.tag, this.product, - }); + String? internalId, + }) : internalId = internalId ?? const Uuid().v4(); factory TagModel.fromJson(Map json) { + final String internalId = json['internalId'] ?? const Uuid().v4(); + return TagModel( uuid: json['uuid'] ?? '', + internalId: internalId, tag: json['tag'] ?? '', product: json['product'] != null ? ProductModel.fromMap(json['product']) @@ -29,4 +35,3 @@ class TagModel { }; } } - diff --git a/lib/pages/spaces_management/tag_model/bloc/add_device_model_bloc.dart b/lib/pages/spaces_management/tag_model/bloc/add_device_model_bloc.dart index 1352e97c..1049fdce 100644 --- a/lib/pages/spaces_management/tag_model/bloc/add_device_model_bloc.dart +++ b/lib/pages/spaces_management/tag_model/bloc/add_device_model_bloc.dart @@ -13,19 +13,19 @@ class AddDeviceTypeModelBloc UpdateProductCountEvent event, Emitter> emit) { final existingProduct = state.firstWhere( (p) => p.productId == event.productId, - orElse: () => SelectedProduct(productId: event.productId, count: 0), + orElse: () => SelectedProduct(productId: event.productId, count: 0,productName: event.productName ), ); if (event.count > 0) { if (!state.contains(existingProduct)) { emit([ ...state, - SelectedProduct(productId: event.productId, count: event.count) + SelectedProduct(productId: event.productId, count: event.count, productName: event.productName) ]); } else { final updatedList = state.map((p) { if (p.productId == event.productId) { - return SelectedProduct(productId: p.productId, count: event.count); + return SelectedProduct(productId: p.productId, count: event.count, productName: p.productName); } return p; }).toList(); diff --git a/lib/pages/spaces_management/tag_model/bloc/add_device_type_model_event.dart b/lib/pages/spaces_management/tag_model/bloc/add_device_type_model_event.dart index a3feaad8..c9594020 100644 --- a/lib/pages/spaces_management/tag_model/bloc/add_device_type_model_event.dart +++ b/lib/pages/spaces_management/tag_model/bloc/add_device_type_model_event.dart @@ -8,8 +8,9 @@ abstract class AddDeviceTypeModelEvent extends Equatable { class UpdateProductCountEvent extends AddDeviceTypeModelEvent { final String productId; final int count; + final String productName; - UpdateProductCountEvent({required this.productId, required this.count}); + UpdateProductCountEvent({required this.productId, required this.count, required this.productName}); @override List get props => [productId, count]; diff --git a/lib/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart b/lib/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart index 32828898..7c9204ef 100644 --- a/lib/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart +++ b/lib/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/common/buttons/cancel_button.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart'; @@ -60,10 +61,8 @@ class AddDeviceTypeModelWidget extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - ActionButton( + CancelButton( label: 'Cancel', - backgroundColor: ColorsManager.boxColor, - foregroundColor: ColorsManager.blackColor, onPressed: () => Navigator.of(context).pop(), ), ActionButton( @@ -71,16 +70,19 @@ class AddDeviceTypeModelWidget extends StatelessWidget { backgroundColor: ColorsManager.secondaryColor, foregroundColor: ColorsManager.whiteColors, onPressed: () async { - print(products); - print("dfsdf"); - await showDialog( - barrierDismissible: false, - context: context, - builder: (context) => AssignTagModelsDialog( - products: products, - subspaces: subspaces, - ), - ); + final currentState = + context.read().state; + if (currentState.isNotEmpty) { + await showDialog( + barrierDismissible: false, + context: context, + builder: (context) => AssignTagModelsDialog( + products: products, + subspaces: subspaces, + addedProducts: currentState, + ), + ); + } }, ), ], diff --git a/lib/pages/spaces_management/tag_model/widgets/device_type_tile_widget.dart b/lib/pages/spaces_management/tag_model/widgets/device_type_tile_widget.dart index 1f39fc22..38159057 100644 --- a/lib/pages/spaces_management/tag_model/widgets/device_type_tile_widget.dart +++ b/lib/pages/spaces_management/tag_model/widgets/device_type_tile_widget.dart @@ -3,7 +3,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/counter_widget.dart'; -import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart'; import 'package:syncrow_web/pages/spaces_management/tag_model/bloc/add_device_model_bloc.dart'; import 'package:syncrow_web/pages/spaces_management/tag_model/bloc/add_device_type_model_event.dart'; import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/device_icon_widget.dart'; @@ -25,7 +24,7 @@ class DeviceTypeTileWidget extends StatelessWidget { Widget build(BuildContext context) { final selectedProduct = productCounts.firstWhere( (p) => p.productId == product.uuid, - orElse: () => SelectedProduct(productId: product.uuid, count: 0), + orElse: () => SelectedProduct(productId: product.uuid, count: 0, productName: product.catName), ); return Card( @@ -49,7 +48,7 @@ class DeviceTypeTileWidget extends StatelessWidget { onCountChanged: (newCount) { context.read().add( UpdateProductCountEvent( - productId: product.uuid, count: newCount), + productId: product.uuid, count: newCount,productName: product.catName), ); }, ),