make counter widget work only for add device

This commit is contained in:
hannathkadher
2025-01-29 09:53:06 +04:00
parent 9091af2661
commit 45b0b67fe0
3 changed files with 27 additions and 49 deletions

View File

@ -12,7 +12,6 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_mod
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
import 'package:syncrow_web/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/action_button_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class AddDeviceTypeWidget extends StatelessWidget {
@ -23,10 +22,12 @@ class AddDeviceTypeWidget extends StatelessWidget {
final List<Tag>? spaceTags;
final List<String>? allTags;
final String spaceName;
final bool isCreate;
final Function(List<Tag>, List<SubspaceModel>?)? onSave;
const AddDeviceTypeWidget(
{super.key,
required this.isCreate,
this.products,
this.initialSelectedProducts,
this.onProductsSelected,
@ -74,7 +75,9 @@ class AddDeviceTypeWidget extends StatelessWidget {
padding:
const EdgeInsets.symmetric(horizontal: 20.0),
child: ScrollableGridViewWidget(
initialProductCounts: state.selectedProducts,
products: products,
isCreate: isCreate,
crossAxisCount: crossAxisCount),
),
),
@ -131,10 +134,7 @@ class AddDeviceTypeWidget extends StatelessWidget {
spaceName: spaceName,
initialTags: initialTags,
title: dialogTitle,
onSave: (tags, subspaces) {
onSave!(tags, subspaces);
},
),
onSave: onSave),
);
}
},
@ -148,29 +148,4 @@ class AddDeviceTypeWidget extends StatelessWidget {
),
));
}
List<Tag> generateInitialTags({
List<Tag>? spaceTags,
List<SubspaceModel>? subspaces,
}) {
final List<Tag> initialTags = [];
if (spaceTags != null) {
initialTags.addAll(spaceTags);
}
if (subspaces != null) {
for (var subspace in subspaces) {
if (subspace.tags != null) {
initialTags.addAll(
subspace.tags!.map(
(tag) => tag.copyWith(location: subspace.subspaceName),
),
);
}
}
}
return initialTags;
}
}

View File

@ -13,12 +13,13 @@ import 'package:syncrow_web/utils/constants/assets.dart';
class DeviceTypeTileWidget extends StatelessWidget {
final ProductModel product;
final List<SelectedProduct> productCounts;
final bool isCreate;
const DeviceTypeTileWidget({
super.key,
const DeviceTypeTileWidget(
{super.key,
required this.product,
required this.productCounts,
});
required this.isCreate});
@override
Widget build(BuildContext context) {
@ -48,7 +49,7 @@ class DeviceTypeTileWidget extends StatelessWidget {
DeviceNameWidget(name: product.name),
const SizedBox(height: 4),
CounterWidget(
isCreate: false,
isCreate: isCreate,
initialCount: selectedProduct.count,
onCountChanged: (newCount) {
context.read<AddDeviceTypeBloc>().add(

View File

@ -10,13 +10,14 @@ class ScrollableGridViewWidget extends StatelessWidget {
final List<ProductModel>? products;
final int crossAxisCount;
final List<SelectedProduct>? initialProductCounts;
final bool isCreate;
const ScrollableGridViewWidget({
super.key,
const ScrollableGridViewWidget(
{super.key,
required this.products,
required this.crossAxisCount,
this.initialProductCounts,
});
required this.isCreate});
@override
Widget build(BuildContext context) {
@ -46,6 +47,7 @@ class ScrollableGridViewWidget extends StatelessWidget {
return DeviceTypeTileWidget(
product: product,
isCreate: isCreate,
productCounts: initialProductCount != null
? [...productCounts, initialProductCount]
: productCounts,