mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fixed tag model
This commit is contained in:
@ -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<SubspaceTemplateModel>? subspaces;
|
||||
final List<TagModel>? initialTags;
|
||||
final ValueChanged<List<TagModel>>? onTagsAssigned;
|
||||
final List<SelectedProduct> 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<AssignTagModelsDialog> {
|
||||
late List<TagModel> tags;
|
||||
late List<SelectedProduct> 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<AssignTagModelsDialog> {
|
||||
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<String>(
|
||||
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<AssignTagModelsDialog> {
|
||||
),
|
||||
DataCell(
|
||||
DropdownButton<String>(
|
||||
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,
|
||||
|
@ -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<String, dynamic> toJson() {
|
||||
return {
|
||||
'productId': productId,
|
||||
'count': count,
|
||||
'productName': productName,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,7 @@ class SpaceModel {
|
||||
return SelectedProduct(
|
||||
productId: product['product']['uuid'],
|
||||
count: product['productCount'],
|
||||
productName: '',
|
||||
);
|
||||
}).toList()
|
||||
: [],
|
||||
|
@ -114,7 +114,7 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
|
||||
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<AddDeviceWidget> {
|
||||
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;
|
||||
}
|
||||
|
@ -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<String, dynamic> 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 {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,19 +13,19 @@ class AddDeviceTypeModelBloc
|
||||
UpdateProductCountEvent event, Emitter<List<SelectedProduct>> 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();
|
||||
|
@ -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<Object> get props => [productId, count];
|
||||
|
@ -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<bool>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => AssignTagModelsDialog(
|
||||
products: products,
|
||||
subspaces: subspaces,
|
||||
),
|
||||
);
|
||||
final currentState =
|
||||
context.read<AddDeviceTypeModelBloc>().state;
|
||||
if (currentState.isNotEmpty) {
|
||||
await showDialog<bool>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => AssignTagModelsDialog(
|
||||
products: products,
|
||||
subspaces: subspaces,
|
||||
addedProducts: currentState,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -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<AddDeviceTypeModelBloc>().add(
|
||||
UpdateProductCountEvent(
|
||||
productId: product.uuid, count: newCount),
|
||||
productId: product.uuid, count: newCount,productName: product.catName),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
Reference in New Issue
Block a user