From 748c67fd8b475530dc75b8abf5df102e022980d2 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 14:52:20 +0300 Subject: [PATCH 01/18] SP-1333 --- .../widgets/tag_chips_display_widget.dart | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index fc6a8c88..fc085237 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -88,12 +88,7 @@ class TagChipDisplay extends StatelessWidget { ), ), ), - EditChip(onTap: () async { - // Use the Navigator's context for showDialog - Navigator.of(context).pop(); - - await showDialog( - barrierDismissible: false, + EditChip(onTap: () => showDialog( context: context, builder: (context) => AssignTagModelsDialog( products: products, @@ -110,18 +105,14 @@ class TagChipDisplay extends StatelessWidget { spaceModel?.tags ?? [], subspaces), spaceName: spaceModel?.modelName ?? '', projectTags: projectTags, - )); - }) + ))) ], ), ), ) : TextButton( - onPressed: () async { - Navigator.of(context).pop(); - - await showDialog( - barrierDismissible: false, + onPressed: () { + showDialog( context: context, builder: (context) => AddDeviceTypeModelWidget( products: products, From 117f6190dd62175b45de191c9d1af24f557dfe30 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:02:58 +0300 Subject: [PATCH 02/18] removed unnecessary `BuildContext` from `TagChipDisplay` constructor, sorted its properies, and converted to using `super.key`. --- .../dialog/create_space_model_dialog.dart | 1 - .../widgets/tag_chips_display_widget.dart | 26 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart index 98251382..3afb0c6f 100644 --- a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart +++ b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart @@ -145,7 +145,6 @@ class CreateSpaceModelDialog extends StatelessWidget { ), const SizedBox(height: 10), TagChipDisplay( - context, screenWidth: screenWidth, spaceModel: updatedSpaceModel, products: products, diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index fc085237..3c1a22ec 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -23,19 +23,19 @@ class TagChipDisplay extends StatelessWidget { final List? allSpaceModels; final List projectTags; - const TagChipDisplay(BuildContext context, - {Key? key, - required this.screenWidth, - required this.spaceModel, - required this.products, - required this.subspaces, - required this.allTags, - required this.spaceNameController, - this.pageContext, - this.otherSpaceModels, - this.allSpaceModels, - required this.projectTags}) - : super(key: key); + const TagChipDisplay({ + required this.screenWidth, + required this.spaceModel, + required this.products, + required this.subspaces, + required this.allTags, + required this.spaceNameController, + required this.projectTags, + this.pageContext, + this.otherSpaceModels, + this.allSpaceModels, + super.key, + }); @override Widget build(BuildContext context) { From 7d0e50fb1d2b0795631fd3c1112c1c32bb645e52 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:03:27 +0300 Subject: [PATCH 03/18] removed unnecessary comments. --- .../space_model/widgets/tag_chips_display_widget.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 3c1a22ec..57dd6318 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -51,14 +51,13 @@ class TagChipDisplay extends StatelessWidget { borderRadius: BorderRadius.circular(15), border: Border.all( color: ColorsManager.textFieldGreyColor, - width: 3.0, // Border width + width: 3.0, ), ), child: Wrap( spacing: 8.0, runSpacing: 8.0, children: [ - // Combine tags from spaceModel and subspaces ...TagHelper.groupTags([ ...?spaceModel?.tags, ...?spaceModel?.subspaceModels?.expand((subspace) => subspace.tags ?? []) @@ -73,7 +72,7 @@ class TagChipDisplay extends StatelessWidget { ), ), label: Text( - 'x${entry.value}', // Show count + 'x${entry.value}', style: Theme.of(context) .textTheme .bodySmall! From 7945cefe5374a0a4152fe939708f3353992d2eb3 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:05:06 +0300 Subject: [PATCH 04/18] added trailing commas wherever necessary. --- .../widgets/tag_chips_display_widget.dart | 78 ++++++++++--------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 57dd6318..98996d5f 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -24,23 +24,24 @@ class TagChipDisplay extends StatelessWidget { final List projectTags; const TagChipDisplay({ - required this.screenWidth, - required this.spaceModel, - required this.products, - required this.subspaces, - required this.allTags, - required this.spaceNameController, - required this.projectTags, - this.pageContext, - this.otherSpaceModels, - this.allSpaceModels, - super.key, - }); + required this.screenWidth, + required this.spaceModel, + required this.products, + required this.subspaces, + required this.allTags, + required this.spaceNameController, + required this.projectTags, + this.pageContext, + this.otherSpaceModels, + this.allSpaceModels, + super.key, + }); @override Widget build(BuildContext context) { return (spaceModel?.tags?.isNotEmpty == true || - spaceModel?.subspaceModels?.any((subspace) => subspace.tags?.isNotEmpty == true) == + spaceModel?.subspaceModels + ?.any((subspace) => subspace.tags?.isNotEmpty == true) == true) ? SizedBox( width: screenWidth * 0.25, @@ -60,7 +61,7 @@ class TagChipDisplay extends StatelessWidget { children: [ ...TagHelper.groupTags([ ...?spaceModel?.tags, - ...?spaceModel?.subspaceModels?.expand((subspace) => subspace.tags ?? []) + ...?spaceModel?.subspaceModels?.expand((e) => e.tags ?? []) ]).entries.map( (entry) => Chip( avatar: SizedBox( @@ -73,10 +74,9 @@ class TagChipDisplay extends StatelessWidget { ), label: Text( 'x${entry.value}', - style: Theme.of(context) - .textTheme - .bodySmall! - .copyWith(color: ColorsManager.spaceColor), + style: Theme.of(context).textTheme.bodySmall!.copyWith( + color: ColorsManager.spaceColor, + ), ), backgroundColor: ColorsManager.whiteColors, shape: RoundedRectangleBorder( @@ -87,24 +87,30 @@ class TagChipDisplay extends StatelessWidget { ), ), ), - EditChip(onTap: () => showDialog( - context: context, - builder: (context) => AssignTagModelsDialog( - products: products, - allSpaceModels: allSpaceModels, - subspaces: subspaces, - pageContext: pageContext, - allTags: allTags, - spaceModel: spaceModel, - otherSpaceModels: otherSpaceModels, - initialTags: TagHelper.generateInitialTags( - subspaces: subspaces, spaceTagModels: spaceModel?.tags ?? []), - title: 'Edit Device', - addedProducts: TagHelper.createInitialSelectedProducts( - spaceModel?.tags ?? [], subspaces), - spaceName: spaceModel?.modelName ?? '', - projectTags: projectTags, - ))) + EditChip( + onTap: () => showDialog( + context: context, + builder: (context) => AssignTagModelsDialog( + products: products, + allSpaceModels: allSpaceModels, + subspaces: subspaces, + pageContext: pageContext, + allTags: allTags, + spaceModel: spaceModel, + otherSpaceModels: otherSpaceModels, + initialTags: TagHelper.generateInitialTags( + subspaces: subspaces, + spaceTagModels: spaceModel?.tags ?? []), + title: 'Edit Device', + addedProducts: TagHelper.createInitialSelectedProducts( + spaceModel?.tags ?? [], + subspaces, + ), + spaceName: spaceModel?.modelName ?? '', + projectTags: projectTags, + ), + ), + ), ], ), ), From c0a963ded5529c5280d8b47737f0ad31b208de40 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:05:31 +0300 Subject: [PATCH 05/18] refactor: use context extension for text theme. --- .../space_model/widgets/tag_chips_display_widget.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 98996d5f..19bdf64f 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -10,6 +10,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_ import 'package:syncrow_web/pages/spaces_management/space_model/widgets/button_content_widget.dart'; import 'package:syncrow_web/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart'; import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/extension/build_context_x.dart'; class TagChipDisplay extends StatelessWidget { final double screenWidth; @@ -74,9 +75,9 @@ class TagChipDisplay extends StatelessWidget { ), label: Text( 'x${entry.value}', - style: Theme.of(context).textTheme.bodySmall!.copyWith( - color: ColorsManager.spaceColor, - ), + style: context.textTheme.bodySmall!.copyWith( + color: ColorsManager.spaceColor, + ), ), backgroundColor: ColorsManager.whiteColors, shape: RoundedRectangleBorder( From a66784473fd16f27ecab567f0691d6a3a9052be0 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:06:01 +0300 Subject: [PATCH 06/18] Replaced conditional with an if statement in `TagChipDisplay`. --- .../widgets/tag_chips_display_widget.dart | 186 +++++++++--------- 1 file changed, 94 insertions(+), 92 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 19bdf64f..b3f3d978 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -40,106 +40,108 @@ class TagChipDisplay extends StatelessWidget { @override Widget build(BuildContext context) { - return (spaceModel?.tags?.isNotEmpty == true || - spaceModel?.subspaceModels - ?.any((subspace) => subspace.tags?.isNotEmpty == true) == - true) - ? SizedBox( - width: screenWidth * 0.25, - child: Container( - padding: const EdgeInsets.all(8.0), - decoration: BoxDecoration( - color: ColorsManager.textFieldGreyColor, - borderRadius: BorderRadius.circular(15), - border: Border.all( - color: ColorsManager.textFieldGreyColor, - width: 3.0, - ), - ), - child: Wrap( - spacing: 8.0, - runSpacing: 8.0, - children: [ - ...TagHelper.groupTags([ - ...?spaceModel?.tags, - ...?spaceModel?.subspaceModels?.expand((e) => e.tags ?? []) - ]).entries.map( - (entry) => Chip( - avatar: SizedBox( - width: 24, - height: 24, - child: SvgPicture.asset( - entry.key.icon ?? 'assets/icons/gateway.svg', - fit: BoxFit.contain, - ), - ), - label: Text( - 'x${entry.value}', - style: context.textTheme.bodySmall!.copyWith( - color: ColorsManager.spaceColor, - ), - ), - backgroundColor: ColorsManager.whiteColors, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - side: const BorderSide( - color: ColorsManager.spaceColor, - ), - ), + if ((spaceModel?.tags?.isNotEmpty == true || + spaceModel?.subspaceModels + ?.any((subspace) => subspace.tags?.isNotEmpty == true) == + true)) { + return SizedBox( + width: screenWidth * 0.25, + child: Container( + padding: const EdgeInsets.all(8.0), + decoration: BoxDecoration( + color: ColorsManager.textFieldGreyColor, + borderRadius: BorderRadius.circular(15), + border: Border.all( + color: ColorsManager.textFieldGreyColor, + width: 3.0, + ), + ), + child: Wrap( + spacing: 8.0, + runSpacing: 8.0, + children: [ + ...TagHelper.groupTags([ + ...?spaceModel?.tags, + ...?spaceModel?.subspaceModels?.expand((e) => e.tags ?? []) + ]).entries.map( + (entry) => Chip( + avatar: SizedBox( + width: 24, + height: 24, + child: SvgPicture.asset( + entry.key.icon ?? 'assets/icons/gateway.svg', + fit: BoxFit.contain, ), ), - EditChip( - onTap: () => showDialog( - context: context, - builder: (context) => AssignTagModelsDialog( - products: products, - allSpaceModels: allSpaceModels, - subspaces: subspaces, - pageContext: pageContext, - allTags: allTags, - spaceModel: spaceModel, - otherSpaceModels: otherSpaceModels, - initialTags: TagHelper.generateInitialTags( - subspaces: subspaces, - spaceTagModels: spaceModel?.tags ?? []), - title: 'Edit Device', - addedProducts: TagHelper.createInitialSelectedProducts( - spaceModel?.tags ?? [], - subspaces, + label: Text( + 'x${entry.value}', + style: context.textTheme.bodySmall!.copyWith( + color: ColorsManager.spaceColor, + ), + ), + backgroundColor: ColorsManager.whiteColors, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + side: const BorderSide( + color: ColorsManager.spaceColor, ), - spaceName: spaceModel?.modelName ?? '', - projectTags: projectTags, ), ), ), - ], - ), - ), - ) - : TextButton( - onPressed: () { - showDialog( - context: context, - builder: (context) => AddDeviceTypeModelWidget( - products: products, - subspaces: subspaces, - allTags: allTags, - spaceName: spaceNameController.text, - pageContext: pageContext, - isCreate: true, - spaceModel: spaceModel, - otherSpaceModels: otherSpaceModels, - projectTags: projectTags, + EditChip( + onTap: () => showDialog( + context: context, + builder: (context) => AssignTagModelsDialog( + products: products, + allSpaceModels: allSpaceModels, + subspaces: subspaces, + pageContext: pageContext, + allTags: allTags, + spaceModel: spaceModel, + otherSpaceModels: otherSpaceModels, + initialTags: TagHelper.generateInitialTags( + subspaces: subspaces, + spaceTagModels: spaceModel?.tags ?? []), + title: 'Edit Device', + addedProducts: TagHelper.createInitialSelectedProducts( + spaceModel?.tags ?? [], + subspaces, + ), + spaceName: spaceModel?.modelName ?? '', + projectTags: projectTags, + ), ), - ); - }, - style: TextButton.styleFrom( - padding: EdgeInsets.zero, - ), - child: const ButtonContentWidget( - icon: Icons.add, - label: 'Add Devices', + ), + ], + ), + ), + ); + } else { + return TextButton( + onPressed: () { + showDialog( + context: context, + builder: (context) => AddDeviceTypeModelWidget( + products: products, + subspaces: subspaces, + allTags: allTags, + spaceName: spaceNameController.text, + pageContext: pageContext, + isCreate: true, + spaceModel: spaceModel, + otherSpaceModels: otherSpaceModels, + projectTags: projectTags, ), ); + }, + style: TextButton.styleFrom( + padding: EdgeInsets.zero, + ), + child: const ButtonContentWidget( + icon: Icons.add, + label: 'Add Devices', + ), + ); + } } } From be168aed9314585f8e4e327c91f09c1262b4a4c6 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:08:30 +0300 Subject: [PATCH 07/18] refactor: simplify tag checking logic to enhance readability. --- .../space_model/widgets/tag_chips_display_widget.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index b3f3d978..1eaa3425 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -40,10 +40,11 @@ class TagChipDisplay extends StatelessWidget { @override Widget build(BuildContext context) { - if ((spaceModel?.tags?.isNotEmpty == true || - spaceModel?.subspaceModels - ?.any((subspace) => subspace.tags?.isNotEmpty == true) == - true)) { + final hasTags = spaceModel?.tags?.isNotEmpty ?? false; + final hasSubspaceTags = + spaceModel?.subspaceModels?.any((e) => e.tags?.isNotEmpty ?? false) ?? false; + + if (hasTags || hasSubspaceTags) { return SizedBox( width: screenWidth * 0.25, child: Container( From f57348e5cda17a30d7fb79d431d6ba533238e9da Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:13:47 +0300 Subject: [PATCH 08/18] converted to using expressions wherever possible in `TagChipDisplay`. --- .../widgets/tag_chips_display_widget.dart | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 1eaa3425..1472a05b 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -38,6 +38,11 @@ class TagChipDisplay extends StatelessWidget { super.key, }); + Map get _groupedTags => TagHelper.groupTags([ + ...?spaceModel?.tags, + ...?spaceModel?.subspaceModels?.expand((e) => e.tags ?? []) + ]); + @override Widget build(BuildContext context) { final hasTags = spaceModel?.tags?.isNotEmpty ?? false; @@ -61,36 +66,33 @@ class TagChipDisplay extends StatelessWidget { spacing: 8.0, runSpacing: 8.0, children: [ - ...TagHelper.groupTags([ - ...?spaceModel?.tags, - ...?spaceModel?.subspaceModels?.expand((e) => e.tags ?? []) - ]).entries.map( - (entry) => Chip( - avatar: SizedBox( - width: 24, - height: 24, - child: SvgPicture.asset( - entry.key.icon ?? 'assets/icons/gateway.svg', - fit: BoxFit.contain, - ), - ), - label: Text( - 'x${entry.value}', - style: context.textTheme.bodySmall!.copyWith( - color: ColorsManager.spaceColor, - ), - ), - backgroundColor: ColorsManager.whiteColors, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - side: const BorderSide( - color: ColorsManager.spaceColor, - ), - ), + ..._groupedTags.entries.map((entry) { + return Chip( + avatar: SizedBox( + width: 24, + height: 24, + child: SvgPicture.asset( + entry.key.icon ?? 'assets/icons/gateway.svg', + fit: BoxFit.contain, ), ), + label: Text( + 'x${entry.value}', + style: context.textTheme.bodySmall!.copyWith( + color: ColorsManager.spaceColor, + ), + ), + backgroundColor: ColorsManager.whiteColors, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + side: const BorderSide( + color: ColorsManager.spaceColor, + ), + ), + ); + }), EditChip( - onTap: () => showDialog( + onTap: () => showDialog( context: context, builder: (context) => AssignTagModelsDialog( products: products, @@ -119,22 +121,20 @@ class TagChipDisplay extends StatelessWidget { ); } else { return TextButton( - onPressed: () { - showDialog( - context: context, - builder: (context) => AddDeviceTypeModelWidget( - products: products, - subspaces: subspaces, - allTags: allTags, - spaceName: spaceNameController.text, - pageContext: pageContext, - isCreate: true, - spaceModel: spaceModel, - otherSpaceModels: otherSpaceModels, - projectTags: projectTags, - ), - ); - }, + onPressed: () => showDialog( + context: context, + builder: (context) => AddDeviceTypeModelWidget( + products: products, + subspaces: subspaces, + allTags: allTags, + spaceName: spaceNameController.text, + pageContext: pageContext, + isCreate: true, + spaceModel: spaceModel, + otherSpaceModels: otherSpaceModels, + projectTags: projectTags, + ), + ), style: TextButton.styleFrom( padding: EdgeInsets.zero, ), From 08e5e17910a6b3e56c207300ba9952b701a42159 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:23:36 +0300 Subject: [PATCH 09/18] Extracted `Add Devices` button into a private method. --- .../widgets/tag_chips_display_widget.dart | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 1472a05b..1f75a047 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -53,18 +53,18 @@ class TagChipDisplay extends StatelessWidget { return SizedBox( width: screenWidth * 0.25, child: Container( - padding: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8), decoration: BoxDecoration( color: ColorsManager.textFieldGreyColor, borderRadius: BorderRadius.circular(15), border: Border.all( color: ColorsManager.textFieldGreyColor, - width: 3.0, + width: 3, ), ), child: Wrap( - spacing: 8.0, - runSpacing: 8.0, + spacing: 8, + runSpacing: 8, children: [ ..._groupedTags.entries.map((entry) { return Chip( @@ -120,29 +120,33 @@ class TagChipDisplay extends StatelessWidget { ), ); } else { - return TextButton( - onPressed: () => showDialog( - context: context, - builder: (context) => AddDeviceTypeModelWidget( - products: products, - subspaces: subspaces, - allTags: allTags, - spaceName: spaceNameController.text, - pageContext: pageContext, - isCreate: true, - spaceModel: spaceModel, - otherSpaceModels: otherSpaceModels, - projectTags: projectTags, - ), - ), - style: TextButton.styleFrom( - padding: EdgeInsets.zero, - ), - child: const ButtonContentWidget( - icon: Icons.add, - label: 'Add Devices', - ), - ); + return _buildAddDevicesButton(context); } } + + Widget _buildAddDevicesButton(BuildContext context) { + return TextButton( + onPressed: () => showDialog( + context: context, + builder: (context) => AddDeviceTypeModelWidget( + products: products, + subspaces: subspaces, + allTags: allTags, + spaceName: spaceNameController.text, + pageContext: pageContext, + isCreate: true, + spaceModel: spaceModel, + otherSpaceModels: otherSpaceModels, + projectTags: projectTags, + ), + ), + style: TextButton.styleFrom( + padding: EdgeInsets.zero, + ), + child: const ButtonContentWidget( + icon: Icons.add, + label: 'Add Devices', + ), + ); + } } From 90e0d2f52be8c575be2b228111a85035130058df Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:24:36 +0300 Subject: [PATCH 10/18] Extracted Chip into a private method. --- .../widgets/tag_chips_display_widget.dart | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 1f75a047..200cd659 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -66,31 +66,7 @@ class TagChipDisplay extends StatelessWidget { spacing: 8, runSpacing: 8, children: [ - ..._groupedTags.entries.map((entry) { - return Chip( - avatar: SizedBox( - width: 24, - height: 24, - child: SvgPicture.asset( - entry.key.icon ?? 'assets/icons/gateway.svg', - fit: BoxFit.contain, - ), - ), - label: Text( - 'x${entry.value}', - style: context.textTheme.bodySmall!.copyWith( - color: ColorsManager.spaceColor, - ), - ), - backgroundColor: ColorsManager.whiteColors, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - side: const BorderSide( - color: ColorsManager.spaceColor, - ), - ), - ); - }), + ..._groupedTags.entries.map((entry) => _buildChip(context, entry)), EditChip( onTap: () => showDialog( context: context, @@ -124,6 +100,35 @@ class TagChipDisplay extends StatelessWidget { } } + Chip _buildChip( + BuildContext context, + MapEntry entry, + ) { + return Chip( + avatar: SizedBox( + width: 24, + height: 24, + child: SvgPicture.asset( + entry.key.icon ?? 'assets/icons/gateway.svg', + fit: BoxFit.contain, + ), + ), + label: Text( + '${entry.value}', + style: context.textTheme.bodySmall!.copyWith( + color: ColorsManager.spaceColor, + ), + ), + backgroundColor: ColorsManager.whiteColors, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + side: const BorderSide( + color: ColorsManager.spaceColor, + ), + ), + ); + } + Widget _buildAddDevicesButton(BuildContext context) { return TextButton( onPressed: () => showDialog( From a4432656ab05cf39351240d1134cb033e65fbc5b Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:25:19 +0300 Subject: [PATCH 11/18] refactor: extract EditChip into a private method for improved readability --- .../widgets/tag_chips_display_widget.dart | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 200cd659..8cf52c4f 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -67,30 +67,7 @@ class TagChipDisplay extends StatelessWidget { runSpacing: 8, children: [ ..._groupedTags.entries.map((entry) => _buildChip(context, entry)), - EditChip( - onTap: () => showDialog( - context: context, - builder: (context) => AssignTagModelsDialog( - products: products, - allSpaceModels: allSpaceModels, - subspaces: subspaces, - pageContext: pageContext, - allTags: allTags, - spaceModel: spaceModel, - otherSpaceModels: otherSpaceModels, - initialTags: TagHelper.generateInitialTags( - subspaces: subspaces, - spaceTagModels: spaceModel?.tags ?? []), - title: 'Edit Device', - addedProducts: TagHelper.createInitialSelectedProducts( - spaceModel?.tags ?? [], - subspaces, - ), - spaceName: spaceModel?.modelName ?? '', - projectTags: projectTags, - ), - ), - ), + _buildEditChip(context), ], ), ), @@ -100,7 +77,35 @@ class TagChipDisplay extends StatelessWidget { } } - Chip _buildChip( + Widget _buildEditChip(BuildContext context) { + return EditChip( + onTap: () => showDialog( + context: context, + builder: (context) => AssignTagModelsDialog( + products: products, + allSpaceModels: allSpaceModels, + subspaces: subspaces, + pageContext: pageContext, + allTags: allTags, + spaceModel: spaceModel, + otherSpaceModels: otherSpaceModels, + initialTags: TagHelper.generateInitialTags( + subspaces: subspaces, + spaceTagModels: spaceModel?.tags ?? [], + ), + title: 'Edit Device', + addedProducts: TagHelper.createInitialSelectedProducts( + spaceModel?.tags ?? [], + subspaces, + ), + spaceName: spaceModel?.modelName ?? '', + projectTags: projectTags, + ), + ), + ); + } + + Widget _buildChip( BuildContext context, MapEntry entry, ) { From d3902d622e2680016440dbadedfae320844925cd Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:27:45 +0300 Subject: [PATCH 12/18] Moved constructor to be the first element in `TagChipDisplay`. --- .../widgets/tag_chips_display_widget.dart | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 8cf52c4f..63eab144 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -13,17 +13,6 @@ import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; class TagChipDisplay extends StatelessWidget { - final double screenWidth; - final SpaceTemplateModel? spaceModel; - final List? products; - final List? subspaces; - final List? allTags; - final TextEditingController spaceNameController; - final BuildContext? pageContext; - final List? otherSpaceModels; - final List? allSpaceModels; - final List projectTags; - const TagChipDisplay({ required this.screenWidth, required this.spaceModel, @@ -38,6 +27,17 @@ class TagChipDisplay extends StatelessWidget { super.key, }); + final double screenWidth; + final SpaceTemplateModel? spaceModel; + final List? products; + final List? subspaces; + final List? allTags; + final TextEditingController spaceNameController; + final BuildContext? pageContext; + final List? otherSpaceModels; + final List? allSpaceModels; + final List projectTags; + Map get _groupedTags => TagHelper.groupTags([ ...?spaceModel?.tags, ...?spaceModel?.subspaceModels?.expand((e) => e.tags ?? []) From 920827d763702884c9b0b49a3111188b95340c97 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:28:12 +0300 Subject: [PATCH 13/18] Removed unnecessary SizedBox from `TagChipDisplay`. --- .../widgets/tag_chips_display_widget.dart | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 63eab144..a369636a 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -50,27 +50,25 @@ class TagChipDisplay extends StatelessWidget { spaceModel?.subspaceModels?.any((e) => e.tags?.isNotEmpty ?? false) ?? false; if (hasTags || hasSubspaceTags) { - return SizedBox( + return Container( width: screenWidth * 0.25, - child: Container( - padding: const EdgeInsets.all(8), - decoration: BoxDecoration( + padding: const EdgeInsets.all(8), + decoration: BoxDecoration( + color: ColorsManager.textFieldGreyColor, + borderRadius: BorderRadius.circular(15), + border: Border.all( color: ColorsManager.textFieldGreyColor, - borderRadius: BorderRadius.circular(15), - border: Border.all( - color: ColorsManager.textFieldGreyColor, - width: 3, - ), - ), - child: Wrap( - spacing: 8, - runSpacing: 8, - children: [ - ..._groupedTags.entries.map((entry) => _buildChip(context, entry)), - _buildEditChip(context), - ], + width: 3, ), ), + child: Wrap( + spacing: 8, + runSpacing: 8, + children: [ + ..._groupedTags.entries.map((entry) => _buildChip(context, entry)), + _buildEditChip(context), + ], + ), ); } else { return _buildAddDevicesButton(context); From fa5bb350c335bb2a38098440e149ef6e7195df08 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:29:25 +0300 Subject: [PATCH 14/18] refactor: replace spaceNameController with spaceName in `TagChipDisplay`. --- .../widgets/dialog/create_space_model_dialog.dart | 2 +- .../space_model/widgets/tag_chips_display_widget.dart | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart index 3afb0c6f..09374855 100644 --- a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart +++ b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart @@ -150,7 +150,7 @@ class CreateSpaceModelDialog extends StatelessWidget { products: products, subspaces: subspaces, allTags: allTags, - spaceNameController: spaceNameController, + spaceName: spaceNameController.text, pageContext: pageContext, otherSpaceModels: otherSpaceModels, allSpaceModels: allSpaceModels, diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index a369636a..f952d289 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -19,7 +19,7 @@ class TagChipDisplay extends StatelessWidget { required this.products, required this.subspaces, required this.allTags, - required this.spaceNameController, + required this.spaceName, required this.projectTags, this.pageContext, this.otherSpaceModels, @@ -32,7 +32,7 @@ class TagChipDisplay extends StatelessWidget { final List? products; final List? subspaces; final List? allTags; - final TextEditingController spaceNameController; + final String spaceName; final BuildContext? pageContext; final List? otherSpaceModels; final List? allSpaceModels; @@ -140,7 +140,7 @@ class TagChipDisplay extends StatelessWidget { products: products, subspaces: subspaces, allTags: allTags, - spaceName: spaceNameController.text, + spaceName: spaceName, pageContext: pageContext, isCreate: true, spaceModel: spaceModel, From db8e5a4aa6b7b340036fd6ca82233a05f86eb522 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:32:31 +0300 Subject: [PATCH 15/18] Refactor `TagChipDisplay._groupedTags` to enhance readabaility. --- .../widgets/tag_chips_display_widget.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index f952d289..7a591695 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -38,10 +38,14 @@ class TagChipDisplay extends StatelessWidget { final List? allSpaceModels; final List projectTags; - Map get _groupedTags => TagHelper.groupTags([ - ...?spaceModel?.tags, - ...?spaceModel?.subspaceModels?.expand((e) => e.tags ?? []) - ]); + Map get _groupedTags { + final spaceTags = spaceModel?.tags ?? []; + + final subspaces = spaceModel?.subspaceModels ?? []; + final subspaceTags = subspaces.expand((e) => e.tags ?? []).toList(); + + return TagHelper.groupTags([...spaceTags, ...subspaceTags]); + } @override Widget build(BuildContext context) { From d1a21be9832dfe566c03d6e0307d82ddb702c149 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:35:24 +0300 Subject: [PATCH 16/18] removed `else` from `TagChipDisplay.build` --- .../space_model/widgets/tag_chips_display_widget.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index 7a591695..ceab79dc 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -74,9 +74,9 @@ class TagChipDisplay extends StatelessWidget { ], ), ); - } else { - return _buildAddDevicesButton(context); } + + return _buildAddDevicesButton(context); } Widget _buildEditChip(BuildContext context) { From 7699453e6d41ae72db413065c02ab43f11b5e000 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:43:50 +0300 Subject: [PATCH 17/18] moved styling of `_buildChip` up, and removed unnecessary `SizedBox`. --- .../widgets/tag_chips_display_widget.dart | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index ceab79dc..ec2a99b1 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -10,6 +10,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_ import 'package:syncrow_web/pages/spaces_management/space_model/widgets/button_content_widget.dart'; import 'package:syncrow_web/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart'; import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; class TagChipDisplay extends StatelessWidget { @@ -112,20 +113,6 @@ class TagChipDisplay extends StatelessWidget { MapEntry entry, ) { return Chip( - avatar: SizedBox( - width: 24, - height: 24, - child: SvgPicture.asset( - entry.key.icon ?? 'assets/icons/gateway.svg', - fit: BoxFit.contain, - ), - ), - label: Text( - '${entry.value}', - style: context.textTheme.bodySmall!.copyWith( - color: ColorsManager.spaceColor, - ), - ), backgroundColor: ColorsManager.whiteColors, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), @@ -133,6 +120,18 @@ class TagChipDisplay extends StatelessWidget { color: ColorsManager.spaceColor, ), ), + avatar: SvgPicture.asset( + entry.key.icon ?? Assets.gateway, + fit: BoxFit.contain, + height: 24, + width: 24, + ), + label: Text( + '${entry.value}', + style: context.textTheme.bodySmall!.copyWith( + color: ColorsManager.spaceColor, + ), + ), ); } From 9044645f952c8ae744840c8c5d5cdd343fb2c744 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 15 Apr 2025 15:45:47 +0300 Subject: [PATCH 18/18] remove screenWidth parameter from `TagChipDisplay` and use `context.screenWidth` instead. --- .../space_model/widgets/dialog/create_space_model_dialog.dart | 1 - .../space_model/widgets/tag_chips_display_widget.dart | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart index 09374855..70dde231 100644 --- a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart +++ b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart @@ -145,7 +145,6 @@ class CreateSpaceModelDialog extends StatelessWidget { ), const SizedBox(height: 10), TagChipDisplay( - screenWidth: screenWidth, spaceModel: updatedSpaceModel, products: products, subspaces: subspaces, diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart index ec2a99b1..86f99e02 100644 --- a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -15,7 +15,6 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart'; class TagChipDisplay extends StatelessWidget { const TagChipDisplay({ - required this.screenWidth, required this.spaceModel, required this.products, required this.subspaces, @@ -28,7 +27,6 @@ class TagChipDisplay extends StatelessWidget { super.key, }); - final double screenWidth; final SpaceTemplateModel? spaceModel; final List? products; final List? subspaces; @@ -56,7 +54,7 @@ class TagChipDisplay extends StatelessWidget { if (hasTags || hasSubspaceTags) { return Container( - width: screenWidth * 0.25, + width: context.screenWidth * 0.25, padding: const EdgeInsets.all(8), decoration: BoxDecoration( color: ColorsManager.textFieldGreyColor,