Merge pull request #144 from SyncrowIOT/SP-1333-FE-set-barrier-dismissable-to-true

Sp 1333 fe set barrier dismissable to true
This commit is contained in:
Faris Armoush
2025-04-17 09:49:11 +03:00
committed by GitHub
2 changed files with 132 additions and 121 deletions

View File

@ -145,13 +145,11 @@ class CreateSpaceModelDialog extends StatelessWidget {
),
const SizedBox(height: 10),
TagChipDisplay(
context,
screenWidth: screenWidth,
spaceModel: updatedSpaceModel,
products: products,
subspaces: subspaces,
allTags: allTags,
spaceNameController: spaceNameController,
spaceName: spaceNameController.text,
pageContext: pageContext,
otherSpaceModels: otherSpaceModels,
allSpaceModels: allSpaceModels,

View File

@ -10,139 +10,152 @@ 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 {
final double screenWidth;
const TagChipDisplay({
required this.spaceModel,
required this.products,
required this.subspaces,
required this.allTags,
required this.spaceName,
required this.projectTags,
this.pageContext,
this.otherSpaceModels,
this.allSpaceModels,
super.key,
});
final SpaceTemplateModel? spaceModel;
final List<ProductModel>? products;
final List<SubspaceTemplateModel>? subspaces;
final List<String>? allTags;
final TextEditingController spaceNameController;
final String spaceName;
final BuildContext? pageContext;
final List<String>? otherSpaceModels;
final List<SpaceTemplateModel>? allSpaceModels;
final List<Tag> 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);
Map<ProductModel, int> get _groupedTags {
final spaceTags = spaceModel?.tags ?? <Tag>[];
final subspaces = spaceModel?.subspaceModels ?? [];
final subspaceTags = subspaces.expand((e) => e.tags ?? <Tag>[]).toList();
return TagHelper.groupTags([...spaceTags, ...subspaceTags]);
}
@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, // Border width
),
),
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 ?? [])
]).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}', // Show count
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: ColorsManager.spaceColor),
),
backgroundColor: ColorsManager.whiteColors,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: const BorderSide(
color: ColorsManager.spaceColor,
),
),
),
),
EditChip(onTap: () async {
// Use the Navigator's context for showDialog
Navigator.of(context).pop();
final hasTags = spaceModel?.tags?.isNotEmpty ?? false;
final hasSubspaceTags =
spaceModel?.subspaceModels?.any((e) => e.tags?.isNotEmpty ?? false) ?? false;
await showDialog<bool>(
barrierDismissible: false,
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,
));
})
],
),
),
)
: TextButton(
onPressed: () async {
Navigator.of(context).pop();
if (hasTags || hasSubspaceTags) {
return Container(
width: context.screenWidth * 0.25,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
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),
],
),
);
}
await showDialog<bool>(
barrierDismissible: false,
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 _buildEditChip(BuildContext context) {
return EditChip(
onTap: () => showDialog<void>(
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<ProductModel, int> entry,
) {
return Chip(
backgroundColor: ColorsManager.whiteColors,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: const BorderSide(
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,
),
),
);
}
Widget _buildAddDevicesButton(BuildContext context) {
return TextButton(
onPressed: () => showDialog<void>(
context: context,
builder: (context) => AddDeviceTypeModelWidget(
products: products,
subspaces: subspaces,
allTags: allTags,
spaceName: spaceName,
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',
),
);
}
}