updated widget

This commit is contained in:
hannathkadher
2025-01-09 16:31:20 +04:00
parent 67516817ec
commit 1ab8c8341d
2 changed files with 134 additions and 96 deletions

View File

@ -8,7 +8,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/add_device_type_widget.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/icon_selection_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/hoverable_button.dart';
import 'package:syncrow_web/utils/asset_validator.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/selected_products_button_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/constants/space_icon_const.dart';
@ -60,8 +60,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
}
@override
@override
Future<Widget> build(BuildContext context) async {
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
return AlertDialog(
@ -92,9 +91,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
),
),
SvgPicture.asset(
await AssetValidator.isValidAsset(selectedIcon)
? selectedIcon
: Assets.location,
selectedIcon,
width: screenWidth * 0.04,
height: screenWidth * 0.04,
),
@ -107,7 +104,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
width: screenWidth * 0.020,
height: screenWidth * 0.020,
decoration: const BoxDecoration(
color: ColorsManager.whiteColors,
color: Colors.white,
shape: BoxShape.circle,
),
child: SvgPicture.asset(
@ -146,8 +143,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
}
});
},
style:
const TextStyle(color: ColorsManager.blackColor),
style: const TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: 'Please enter the name',
hintStyle: const TextStyle(
@ -199,7 +195,16 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
),
const SizedBox(height: 16),
if (selectedProducts.isNotEmpty)
_buildSelectedProductsButtons(widget.products ?? [])
SelectedProductsButtons(
products: widget.products ?? [],
selectedProducts: selectedProducts,
onProductsUpdated: (updatedProducts) {
setState(() {
selectedProducts = updatedProducts;
});
},
context: context,
)
else
DefaultButton(
onPressed: () {
@ -216,7 +221,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
);
},
backgroundColor: ColorsManager.textFieldGreyColor,
foregroundColor: ColorsManager.blackColor,
foregroundColor: Colors.black,
borderColor: ColorsManager.neutralGray,
borderRadius: 16.0,
padding: 10.0, // Reduced padding for smaller size
@ -317,74 +322,6 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
);
}
Widget _buildSelectedProductsButtons(List<ProductModel> products) {
final screenWidth = MediaQuery.of(context).size.width;
return Container(
width: screenWidth * 0.6,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: ColorsManager.textFieldGreyColor,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: ColorsManager.neutralGray,
width: 2,
),
),
child: Wrap(
spacing: 8,
runSpacing: 8,
children: [
for (var i = 0; i < selectedProducts.length; i++) ...[
HoverableButton(
iconPath:
_mapIconToProduct(selectedProducts[i].productId, products),
text: 'x${selectedProducts[i].count}',
onTap: () {
setState(() {
selectedProducts.remove(selectedProducts[i]);
});
// Handle button tap
},
),
if (i < selectedProducts.length - 1)
const SizedBox(
width: 2), // Add space except after the last button
],
const SizedBox(width: 2),
GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (context) => AddDeviceWidget(
products: widget.products,
initialSelectedProducts: selectedProducts,
onProductsSelected: (selectedProductsMap) {
setState(() {
selectedProducts = selectedProductsMap;
});
},
),
);
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: ColorsManager.whiteColors,
borderRadius: BorderRadius.circular(16),
),
child: const Icon(
Icons.add,
color: ColorsManager.spaceColor,
size: 24,
),
),
),
],
),
);
}
bool _isNameConflict(String value) {
return (widget.parentSpace?.children.any((child) => child.name == value) ??
false) ||
@ -393,21 +330,4 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
(widget.editSpace?.children.any((child) => child.name == value) ??
false);
}
String _mapIconToProduct(String uuid, List<ProductModel> products) {
// Find the product with the matching UUID
final product = products.firstWhere(
(product) => product.uuid == uuid,
orElse: () => ProductModel(
uuid: '',
catName: '',
prodId: '',
prodType: '',
name: '',
icon: Assets.presenceSensor,
),
);
return product.icon ?? Assets.presenceSensor;
}
}