fixed device type counts

This commit is contained in:
hannathkadher
2024-11-20 20:41:12 +04:00
parent 60710c383f
commit 6fd845a9fc
2 changed files with 165 additions and 62 deletions

View File

@ -42,7 +42,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
width: 100, width: 100,
height: 100, height: 100,
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: Color(0xFFF5F6F7), color: ColorsManager.boxColor,
shape: BoxShape.circle, shape: BoxShape.circle,
), ),
), ),
@ -87,12 +87,12 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
color: ColorsManager.lightGrayColor, color: ColorsManager.lightGrayColor,
fontWeight: FontWeight.w400), fontWeight: FontWeight.w400),
filled: true, filled: true,
fillColor: const Color(0xFFF5F6F7), fillColor: ColorsManager.boxColor,
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide( borderSide: const BorderSide(
color: color: ColorsManager
Color(0xFFF5F6F7), // Light gray color when enabled (not focused) .boxColor, // Light gray color when enabled (not focused)
width: 1.5, width: 1.5,
), ),
), ),
@ -100,7 +100,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide( borderSide: const BorderSide(
color: Color(0xFFF5F6F7), // Primary color when focused color: ColorsManager.boxColor, // Primary color when focused
width: 1.5, width: 1.5,
), ),
), ),
@ -108,7 +108,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
disabledBorder: OutlineInputBorder( disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide( borderSide: const BorderSide(
color: Color(0xFFF5F6F7), // Light gray for disabled state color: ColorsManager.boxColor, // Light gray for disabled state
width: 1.5, width: 1.5,
), ),
), ),
@ -116,7 +116,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
errorBorder: OutlineInputBorder( errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide( borderSide: const BorderSide(
color: Color(0xFFF5F6F7), // Red border when there's an error color: ColorsManager.boxColor, // Red border when there's an error
width: 1.5, width: 1.5,
), ),
), ),
@ -124,7 +124,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
focusedErrorBorder: OutlineInputBorder( focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide( borderSide: const BorderSide(
color: ColorsManager.boxColor, // Red border when there's an error and it's focused color: ColorsManager
.boxColor, // Red border when there's an error and it's focused
width: 1.5, width: 1.5,
), ),
), ),
@ -132,55 +133,59 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
// Add Devices or Space Model Button // Add Devices or Space Model Button
ElevatedButton( if (selectedProducts.isNotEmpty)
onPressed: () { _buildSelectedProductsButtons(widget.products ?? [])
showDialog( else
context: context, ElevatedButton(
builder: (context) => AddDeviceWidget( onPressed: () {
products: widget.products, showDialog(
onProductsSelected: (selectedProductsMap) { context: context,
setState(() { builder: (context) => AddDeviceWidget(
selectedProducts = selectedProductsMap; products: widget.products,
}); onProductsSelected: (selectedProductsMap) {
}, setState(() {
), selectedProducts = selectedProductsMap;
); });
}, },
style: ElevatedButton.styleFrom(
backgroundColor: ColorsManager.textFieldGreyColor,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20),
shape: RoundedRectangleBorder(
side: const BorderSide(
// Add border side here
color: ColorsManager.neutralGray, // Define your desired border color
width: 2.0, // Define border width
), ),
borderRadius: BorderRadius.circular(20)), );
), },
child: Row( style: ElevatedButton.styleFrom(
mainAxisSize: backgroundColor: ColorsManager.textFieldGreyColor,
MainAxisSize.min, // Adjust the button size to fit the content padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20),
children: [ shape: RoundedRectangleBorder(
SvgPicture.asset( side: const BorderSide(
Assets.addIcon, // Replace with your actual icon path // Add border side here
width: 20, // Set the size of the icon color:
height: 20, ColorsManager.neutralGray, // Define your desired border color
), width: 2.0, // Define border width
const SizedBox(width: 8), // Add spacing between the icon and text ),
const Text( borderRadius: BorderRadius.circular(20)),
'Add devices / Assign a space model', ),
style: TextStyle( child: Row(
color: Colors.black, mainAxisSize:
fontSize: 16, MainAxisSize.min, // Adjust the button size to fit the content
fontFamily: 'Aftika', children: [
fontWeight: FontWeight.w400, SvgPicture.asset(
height: 1.5, // Adjust line height for better spacing Assets.addIcon, // Replace with your actual icon path
width: 20, // Set the size of the icon
height: 20,
), ),
), const SizedBox(width: 8), // Add spacing between the icon and text
const SizedBox(width: 8), const Text(
], 'Add devices / Assign a space model',
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: 'Aftika',
fontWeight: FontWeight.w400,
height: 1.5, // Adjust line height for better spacing
),
),
const SizedBox(width: 8),
],
),
), ),
),
], ],
), ),
), ),
@ -231,7 +236,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
height: 200, height: 200,
padding: const EdgeInsets.all(18), padding: const EdgeInsets.all(18),
decoration: BoxDecoration( decoration: BoxDecoration(
color: const Color(0xFFF5F6F7), color: ColorsManager.boxColor,
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
), ),
child: GridView.builder( child: GridView.builder(
@ -263,6 +268,104 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
); );
} }
Widget _buildSelectedProductsButtons(List<ProductModel> products) {
return Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: ColorsManager.textFieldGreyColor,
borderRadius: BorderRadius.circular(12),
),
child: Wrap(
spacing: 8, // Horizontal spacing between buttons
runSpacing: 8, // Vertical spacing between rows
children: [
// Dynamically create a button for each selected product
for (var entry in selectedProducts.entries)
GestureDetector(
onTap: () {
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
// Display the product icon
SvgPicture.asset(
_mapIconToProduct(entry.key, products),
width: 24,
height: 24,
),
const SizedBox(width: 8),
// Display the product count
Text(
'x${entry.value}',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: ColorsManager.spaceColor,
),
),
],
),
),
),
// Add Button
GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (context) => AddDeviceWidget(
products: widget.products,
initialSelectedProducts: selectedProducts,
onProductsSelected: (selectedProductsMap) {
setState(() {
selectedProducts = selectedProductsMap;
});
},
),
);
},
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: ColorsManager.textFieldGreyColor,
borderRadius: BorderRadius.circular(16),
),
child: const Icon(
Icons.add,
color: ColorsManager.spaceColor,
size: 24,
),
),
),
],
),
);
}
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;
}
final List<String> _iconList = [ final List<String> _iconList = [
Assets.location, Assets.location,
Assets.villa, Assets.villa,

View File

@ -10,8 +10,10 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart';
class AddDeviceWidget extends StatefulWidget { class AddDeviceWidget extends StatefulWidget {
final List<ProductModel>? products; final List<ProductModel>? products;
final ValueChanged<Map<String, int>>? onProductsSelected; final ValueChanged<Map<String, int>>? onProductsSelected;
final Map<String, int>? initialSelectedProducts;
const AddDeviceWidget({super.key, this.products, this.onProductsSelected}); const AddDeviceWidget(
{super.key, this.products, this.initialSelectedProducts, this.onProductsSelected});
@override @override
_AddDeviceWidgetState createState() => _AddDeviceWidgetState(); _AddDeviceWidgetState createState() => _AddDeviceWidgetState();
@ -25,11 +27,9 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
void initState() { void initState() {
super.initState(); super.initState();
_scrollController = ScrollController(); _scrollController = ScrollController();
print(widget.initialSelectedProducts);
if (widget.products != null) { if (widget.initialSelectedProducts != null && widget.initialSelectedProducts!.isNotEmpty) {
for (var product in widget.products!) { productCounts = widget.initialSelectedProducts!;
productCounts[product.uuid] = 0;
}
} }
} }
@ -161,7 +161,7 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
const SizedBox(height: 8), const SizedBox(height: 8),
// The custom counter widget aligned at the bottom // The custom counter widget aligned at the bottom
CounterWidget( CounterWidget(
initialCount: 0, initialCount: productCounts[deviceType!.uuid] ?? 0,
onCountChanged: (newCount) { onCountChanged: (newCount) {
setState(() { setState(() {
if (newCount > 0) { if (newCount > 0) {