diff --git a/lib/pages/space_management_v2/modules/tags/presentation/widgets/assign_tags_table.dart b/lib/pages/space_management_v2/modules/tags/presentation/widgets/assign_tags_table.dart index 1711e019..e37de217 100644 --- a/lib/pages/space_management_v2/modules/tags/presentation/widgets/assign_tags_table.dart +++ b/lib/pages/space_management_v2/modules/tags/presentation/widgets/assign_tags_table.dart @@ -31,173 +31,178 @@ class AssignTagsTable extends StatelessWidget { DataColumn _buildDataColumn(BuildContext context, String label) { return DataColumn( - label: SelectableText(label, style: context.textTheme.bodyMedium), + label: Expanded( + child: FittedBox( + alignment: AlignmentDirectional.centerStart, + fit: BoxFit.scaleDown, + child: SelectableText(label, style: context.textTheme.bodyMedium), + ), + ), ); } @override Widget build(BuildContext context) { return BlocProvider( - create: (BuildContext context) => TagsBloc( + create: (context) => TagsBloc( RemoteTagsService(HTTPService()), )..add(const LoadTags()), child: BlocBuilder( - builder: (context, state) { - return switch (state) { - TagsLoading() || TagsInitial() => const Center( - child: CircularProgressIndicator(), - ), - TagsFailure(:final message) => Center( - child: Text(message), - ), - TagsLoaded(:final tags) => ClipRRect( - borderRadius: BorderRadius.circular(20), - child: DataTable( - headingRowColor: WidgetStateProperty.all( - ColorsManager.dataHeaderGrey, - ), - key: ValueKey(productAllocations.length), - border: TableBorder.all( - color: ColorsManager.dataHeaderGrey, - width: 1, - borderRadius: BorderRadius.circular(20), - ), - columns: [ - _buildDataColumn(context, '#'), - _buildDataColumn(context, 'Device'), - _buildDataColumn(context, 'Tag'), - _buildDataColumn(context, 'Location'), - ], - rows: productAllocations.isEmpty - ? [ - DataRow( - cells: [ - DataCell( - Center( - child: SelectableText( - 'No Devices Available', - style: context.textTheme.bodyMedium?.copyWith( - color: ColorsManager.lightGrayColor, - ), - ), - ), - ), - DataCell.empty, - DataCell.empty, - DataCell.empty, - ], - ), - ] - : List.generate(productAllocations.length, (index) { - final productAllocation = productAllocations[index]; - final allocationUuid = productAllocation.uuid; - - final availableTags = tags - .where( - (tag) => - !productAllocations - .where((p) => - p.product.productType == - productAllocation.product.productType) - .map((p) => p.tag.name.toLowerCase()) - .contains(tag.name.toLowerCase()) || - tag.uuid == productAllocation.tag.uuid, - ) - .toList(); - - final currentLocationUuid = - productLocations[allocationUuid]; - final currentLocationName = currentLocationUuid == null - ? 'Main Space' - : subspaces - .firstWhere((s) => s.uuid == currentLocationUuid) - .name; - - return DataRow( - key: ValueKey(allocationUuid), - cells: [ - DataCell(Text((index + 1).toString())), - DataCell( - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Text( - productAllocation.product.name, - overflow: TextOverflow.ellipsis, - )), - const SizedBox(width: 10), - Container( - width: 20, - height: 20, - decoration: BoxDecoration( - shape: BoxShape.circle, - border: Border.all( - color: ColorsManager.lightGrayColor, - width: 1, - ), - ), - child: IconButton( - icon: const Icon( - Icons.close, - color: ColorsManager.lightGreyColor, - size: 16, - ), - onPressed: () { - onProductDeleted(allocationUuid); - }, - tooltip: 'Delete Tag', - padding: EdgeInsets.zero, - constraints: const BoxConstraints(), - ), - ), - ], - ), - ), - DataCell( - Container( - alignment: Alignment.centerLeft, - width: double.infinity, - child: ProductTagField( - key: ValueKey('dropdown_$allocationUuid'), - productName: productAllocation.product.uuid, - initialValue: productAllocation.tag, - onSelected: (newTag) { - onTagSelected(allocationUuid, newTag); - }, - items: availableTags, - ), - ), - ), - DataCell( - SizedBox( - width: double.infinity, - child: DialogDropdown( - items: [ - 'Main Space', - ...subspaces.map((s) => s.name) - ], - selectedValue: currentLocationName, - onSelected: (newLocationName) { - final newSubspaceUuid = newLocationName == - 'Main Space' - ? null - : subspaces - .firstWhere( - (s) => s.name == newLocationName) - .uuid; - onLocationSelected( - allocationUuid, newSubspaceUuid); - }, - )), - ), - ], - ); - }), + builder: (context, state) => switch (state) { + TagsLoading() || TagsInitial() => const Center( + child: CircularProgressIndicator(), + ), + TagsFailure(:final message) => Center( + child: Text(message), + ), + TagsLoaded(:final tags) => ClipRRect( + borderRadius: BorderRadius.circular(20), + child: DataTable( + headingRowColor: WidgetStateProperty.all( + ColorsManager.dataHeaderGrey, ), + key: ValueKey(productAllocations.length), + border: TableBorder.all( + color: ColorsManager.dataHeaderGrey, + width: 1, + borderRadius: BorderRadius.circular(20), + ), + columns: [ + _buildDataColumn(context, '#'), + _buildDataColumn(context, 'Device'), + _buildDataColumn(context, 'Tag'), + _buildDataColumn(context, 'Location'), + ], + rows: productAllocations.isEmpty + ? [ + DataRow( + cells: [ + DataCell( + FittedBox( + alignment: AlignmentDirectional.centerStart, + fit: BoxFit.scaleDown, + child: SelectableText( + 'No Devices Available', + style: context.textTheme.bodyMedium?.copyWith( + color: ColorsManager.lightGrayColor, + ), + ), + ), + ), + DataCell.empty, + DataCell.empty, + DataCell.empty, + ], + ), + ] + : List.generate(productAllocations.length, (index) { + final productAllocation = productAllocations[index]; + final allocationUuid = productAllocation.uuid; + + final availableTags = tags + .where( + (tag) => + !productAllocations + .where((p) => + p.product.productType == + productAllocation.product.productType) + .map((p) => p.tag.name.toLowerCase()) + .contains(tag.name.toLowerCase()) || + tag.uuid == productAllocation.tag.uuid, + ) + .toList(); + + final currentLocationUuid = productLocations[allocationUuid]; + final currentLocationName = currentLocationUuid == null + ? 'Main Space' + : subspaces + .firstWhere((s) => s.uuid == currentLocationUuid) + .name; + + return DataRow( + key: ValueKey(allocationUuid), + cells: [ + DataCell(Text((index + 1).toString())), + DataCell( + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Text( + productAllocation.product.name, + overflow: TextOverflow.ellipsis, + )), + const SizedBox(width: 10), + Container( + width: 20, + height: 20, + decoration: BoxDecoration( + shape: BoxShape.circle, + border: Border.all( + color: ColorsManager.lightGrayColor, + width: 1, + ), + ), + child: IconButton( + icon: const Icon( + Icons.close, + color: ColorsManager.lightGreyColor, + size: 16, + ), + onPressed: () { + onProductDeleted(allocationUuid); + }, + tooltip: 'Delete Tag', + padding: EdgeInsets.zero, + constraints: const BoxConstraints(), + ), + ), + ], + ), + ), + DataCell( + Container( + alignment: Alignment.centerLeft, + width: double.infinity, + child: ProductTagField( + key: ValueKey('dropdown_$allocationUuid'), + productName: productAllocation.product.uuid, + initialValue: productAllocation.tag, + onSelected: (newTag) { + onTagSelected(allocationUuid, newTag); + }, + items: availableTags, + ), + ), + ), + DataCell( + SizedBox( + width: double.infinity, + child: DialogDropdown( + items: [ + 'Main Space', + ...subspaces.map((s) => s.name) + ], + selectedValue: currentLocationName, + onSelected: (newLocationName) { + final newSubspaceUuid = newLocationName == + 'Main Space' + ? null + : subspaces + .firstWhere( + (s) => s.name == newLocationName) + .uuid; + onLocationSelected( + allocationUuid, newSubspaceUuid); + }, + )), + ), + ], + ); + }), ), - _ => const SizedBox.shrink(), - }; + ), + _ => const SizedBox.shrink(), }, ), );