converted to using expressions wherever possible in TagChipDisplay.

This commit is contained in:
Faris Armoush
2025-04-15 15:13:47 +03:00
parent be168aed93
commit f57348e5cd

View File

@ -38,6 +38,11 @@ class TagChipDisplay extends StatelessWidget {
super.key, super.key,
}); });
Map<ProductModel, int> get _groupedTags => TagHelper.groupTags([
...?spaceModel?.tags,
...?spaceModel?.subspaceModels?.expand((e) => e.tags ?? [])
]);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final hasTags = spaceModel?.tags?.isNotEmpty ?? false; final hasTags = spaceModel?.tags?.isNotEmpty ?? false;
@ -61,36 +66,33 @@ class TagChipDisplay extends StatelessWidget {
spacing: 8.0, spacing: 8.0,
runSpacing: 8.0, runSpacing: 8.0,
children: [ children: [
...TagHelper.groupTags([ ..._groupedTags.entries.map((entry) {
...?spaceModel?.tags, return Chip(
...?spaceModel?.subspaceModels?.expand((e) => e.tags ?? []) avatar: SizedBox(
]).entries.map( width: 24,
(entry) => Chip( height: 24,
avatar: SizedBox( child: SvgPicture.asset(
width: 24, entry.key.icon ?? 'assets/icons/gateway.svg',
height: 24, fit: BoxFit.contain,
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,
),
),
), ),
), ),
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( EditChip(
onTap: () => showDialog<bool>( onTap: () => showDialog<void>(
context: context, context: context,
builder: (context) => AssignTagModelsDialog( builder: (context) => AssignTagModelsDialog(
products: products, products: products,
@ -119,22 +121,20 @@ class TagChipDisplay extends StatelessWidget {
); );
} else { } else {
return TextButton( return TextButton(
onPressed: () { onPressed: () => showDialog<void>(
showDialog<void>( context: context,
context: context, builder: (context) => AddDeviceTypeModelWidget(
builder: (context) => AddDeviceTypeModelWidget( products: products,
products: products, subspaces: subspaces,
subspaces: subspaces, allTags: allTags,
allTags: allTags, spaceName: spaceNameController.text,
spaceName: spaceNameController.text, pageContext: pageContext,
pageContext: pageContext, isCreate: true,
isCreate: true, spaceModel: spaceModel,
spaceModel: spaceModel, otherSpaceModels: otherSpaceModels,
otherSpaceModels: otherSpaceModels, projectTags: projectTags,
projectTags: projectTags, ),
), ),
);
},
style: TextButton.styleFrom( style: TextButton.styleFrom(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
), ),