fixed tag model

This commit is contained in:
hannathkadher
2025-01-05 21:16:59 +04:00
parent 5bd257ee56
commit 0fda5457ae
9 changed files with 53 additions and 41 deletions

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; 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/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/subspace_template_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart';
import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/color_manager.dart';
@ -9,11 +10,13 @@ class AssignTagModelsDialog extends StatefulWidget {
final List<SubspaceTemplateModel>? subspaces; final List<SubspaceTemplateModel>? subspaces;
final List<TagModel>? initialTags; final List<TagModel>? initialTags;
final ValueChanged<List<TagModel>>? onTagsAssigned; final ValueChanged<List<TagModel>>? onTagsAssigned;
final List<SelectedProduct> addedProducts;
const AssignTagModelsDialog({ const AssignTagModelsDialog({
Key? key, Key? key,
required this.products, required this.products,
required this.subspaces, required this.subspaces,
required this.addedProducts,
this.initialTags, this.initialTags,
this.onTagsAssigned, this.onTagsAssigned,
}) : super(key: key); }) : super(key: key);
@ -24,15 +27,17 @@ class AssignTagModelsDialog extends StatefulWidget {
class AssignTagModelsDialogState extends State<AssignTagModelsDialog> { class AssignTagModelsDialogState extends State<AssignTagModelsDialog> {
late List<TagModel> tags; late List<TagModel> tags;
late List<SelectedProduct> selectedProducts;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (widget.products != null) { if (widget.products != null) {
print(widget.products); print(widget.products);
tags = []; tags = [];
} }
selectedProducts = widget.addedProducts;
} }
@override @override
@ -50,19 +55,18 @@ class AssignTagModelsDialogState extends State<AssignTagModelsDialog> {
DataColumn(label: Text('Tag')), DataColumn(label: Text('Tag')),
DataColumn(label: Text('Location')), DataColumn(label: Text('Location')),
], ],
rows: tags.asMap().entries.map((entry) { rows: selectedProducts.asMap().entries.map((entry) {
final index = entry.key + 1; final index = entry.key + 1;
final tagModel = entry.value; final selectedProduct = entry.value;
return DataRow(cells: [ return DataRow(cells: [
DataCell(Text(index.toString())), DataCell(Text(index.toString())),
DataCell(Text(tagModel.product?.name ?? 'Unknown')), DataCell(Text(selectedProduct.productName ?? 'Unknown')),
DataCell( DataCell(
DropdownButton<String>( DropdownButton<String>(
value: tagModel.tag, value:
'Tag 1', // Static text that matches an item in the list
onChanged: (value) { onChanged: (value) {
setState(() { // Handle value change if needed
tagModel.tag = value!;
});
}, },
items: List.generate(10, (index) { items: List.generate(10, (index) {
final tag = 'Tag ${index + 1}'; final tag = 'Tag ${index + 1}';
@ -72,14 +76,12 @@ class AssignTagModelsDialogState extends State<AssignTagModelsDialog> {
), ),
DataCell( DataCell(
DropdownButton<String>( DropdownButton<String>(
value: widget.subspaces value: widget.subspaces?.isNotEmpty == true
?.firstWhere( ? widget.subspaces!.first.subspaceName
(subspace) => : null,
subspace.subspaceName == 'ssdsdf', onChanged: (value) {
) // Handle value changes here
.subspaceName ?? },
'None',
onChanged: (value) {},
items: widget.subspaces! items: widget.subspaces!
.map((subspace) => DropdownMenuItem( .map((subspace) => DropdownMenuItem(
value: subspace.subspaceName, value: subspace.subspaceName,

View File

@ -1,13 +1,15 @@
class SelectedProduct { class SelectedProduct {
final String productId; final String productId;
int count; int count;
final String productName;
SelectedProduct({required this.productId, required this.count}); SelectedProduct({required this.productId, required this.count, required this.productName});
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
'productId': productId, 'productId': productId,
'count': count, 'count': count,
'productName': productName,
}; };
} }

View File

@ -90,6 +90,7 @@ class SpaceModel {
return SelectedProduct( return SelectedProduct(
productId: product['product']['uuid'], productId: product['product']['uuid'],
count: product['productCount'], count: product['productCount'],
productName: '',
); );
}).toList() }).toList()
: [], : [],

View File

@ -114,7 +114,7 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
Widget _buildDeviceTypeTile(ProductModel product, Size size) { Widget _buildDeviceTypeTile(ProductModel product, Size size) {
final selectedProduct = productCounts.firstWhere( final selectedProduct = productCounts.firstWhere(
(p) => p.productId == product.uuid, (p) => p.productId == product.uuid,
orElse: () => SelectedProduct(productId: product.uuid, count: 0), orElse: () => SelectedProduct(productId: product.uuid, count: 0, productName: product.catName),
); );
return SizedBox( return SizedBox(
@ -143,7 +143,7 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
if (newCount > 0) { if (newCount > 0) {
if (!productCounts.contains(selectedProduct)) { if (!productCounts.contains(selectedProduct)) {
productCounts productCounts
.add(SelectedProduct(productId: product.uuid, count: newCount)); .add(SelectedProduct(productId: product.uuid, count: newCount, productName: product.catName));
} else { } else {
selectedProduct.count = newCount; selectedProduct.count = newCount;
} }

View File

@ -1,19 +1,25 @@
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
import 'package:uuid/uuid.dart';
class TagModel { class TagModel {
String? uuid; String? uuid;
String tag; String tag;
final ProductModel? product; final ProductModel? product;
String internalId;
TagModel({ TagModel({
this.uuid, this.uuid,
required this.tag, required this.tag,
this.product, this.product,
}); String? internalId,
}) : internalId = internalId ?? const Uuid().v4();
factory TagModel.fromJson(Map<String, dynamic> json) { factory TagModel.fromJson(Map<String, dynamic> json) {
final String internalId = json['internalId'] ?? const Uuid().v4();
return TagModel( return TagModel(
uuid: json['uuid'] ?? '', uuid: json['uuid'] ?? '',
internalId: internalId,
tag: json['tag'] ?? '', tag: json['tag'] ?? '',
product: json['product'] != null product: json['product'] != null
? ProductModel.fromMap(json['product']) ? ProductModel.fromMap(json['product'])
@ -29,4 +35,3 @@ class TagModel {
}; };
} }
} }

View File

@ -13,19 +13,19 @@ class AddDeviceTypeModelBloc
UpdateProductCountEvent event, Emitter<List<SelectedProduct>> emit) { UpdateProductCountEvent event, Emitter<List<SelectedProduct>> emit) {
final existingProduct = state.firstWhere( final existingProduct = state.firstWhere(
(p) => p.productId == event.productId, (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 (event.count > 0) {
if (!state.contains(existingProduct)) { if (!state.contains(existingProduct)) {
emit([ emit([
...state, ...state,
SelectedProduct(productId: event.productId, count: event.count) SelectedProduct(productId: event.productId, count: event.count, productName: event.productName)
]); ]);
} else { } else {
final updatedList = state.map((p) { final updatedList = state.map((p) {
if (p.productId == event.productId) { 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; return p;
}).toList(); }).toList();

View File

@ -8,8 +8,9 @@ abstract class AddDeviceTypeModelEvent extends Equatable {
class UpdateProductCountEvent extends AddDeviceTypeModelEvent { class UpdateProductCountEvent extends AddDeviceTypeModelEvent {
final String productId; final String productId;
final int count; final int count;
final String productName;
UpdateProductCountEvent({required this.productId, required this.count}); UpdateProductCountEvent({required this.productId, required this.count, required this.productName});
@override @override
List<Object> get props => [productId, count]; List<Object> get props => [productId, count];

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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/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/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/model/selected_product_model.dart';
@ -60,10 +61,8 @@ class AddDeviceTypeModelWidget extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
ActionButton( CancelButton(
label: 'Cancel', label: 'Cancel',
backgroundColor: ColorsManager.boxColor,
foregroundColor: ColorsManager.blackColor,
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
ActionButton( ActionButton(
@ -71,16 +70,19 @@ class AddDeviceTypeModelWidget extends StatelessWidget {
backgroundColor: ColorsManager.secondaryColor, backgroundColor: ColorsManager.secondaryColor,
foregroundColor: ColorsManager.whiteColors, foregroundColor: ColorsManager.whiteColors,
onPressed: () async { onPressed: () async {
print(products); final currentState =
print("dfsdf"); context.read<AddDeviceTypeModelBloc>().state;
await showDialog<bool>( if (currentState.isNotEmpty) {
barrierDismissible: false, await showDialog<bool>(
context: context, barrierDismissible: false,
builder: (context) => AssignTagModelsDialog( context: context,
products: products, builder: (context) => AssignTagModelsDialog(
subspaces: subspaces, products: products,
), subspaces: subspaces,
); addedProducts: currentState,
),
);
}
}, },
), ),
], ],

View File

@ -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/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/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/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_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/bloc/add_device_type_model_event.dart';
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/device_icon_widget.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) { Widget build(BuildContext context) {
final selectedProduct = productCounts.firstWhere( final selectedProduct = productCounts.firstWhere(
(p) => p.productId == product.uuid, (p) => p.productId == product.uuid,
orElse: () => SelectedProduct(productId: product.uuid, count: 0), orElse: () => SelectedProduct(productId: product.uuid, count: 0, productName: product.catName),
); );
return Card( return Card(
@ -49,7 +48,7 @@ class DeviceTypeTileWidget extends StatelessWidget {
onCountChanged: (newCount) { onCountChanged: (newCount) {
context.read<AddDeviceTypeModelBloc>().add( context.read<AddDeviceTypeModelBloc>().add(
UpdateProductCountEvent( UpdateProductCountEvent(
productId: product.uuid, count: newCount), productId: product.uuid, count: newCount,productName: product.catName),
); );
}, },
), ),