edit tag model pop up

This commit is contained in:
hannathkadher
2025-01-07 19:07:42 +04:00
parent 1228e5e737
commit 08f322165e
6 changed files with 190 additions and 37 deletions

View File

@ -298,7 +298,23 @@ class AssignTagModelsDialog extends StatelessWidget {
onPressed: state.isSaveEnabled
? () async {
Navigator.of(context).pop();
final assignedTags = <TagModel>{};
for (var tag in state.tags) {
if (tag.location == null ||
subspaces == null) {
continue;
}
for (var subspace in subspaces!) {
if (tag.location == subspace.subspaceName) {
subspace.tags ??= [];
subspace.tags!.add(tag);
assignedTags.add(tag);
break;
}
}
}
state.tags.removeWhere(assignedTags.contains);
await showDialog(
barrierDismissible: false,
context: context,

View File

@ -7,7 +7,7 @@ import 'package:uuid/uuid.dart';
class SpaceTemplateModel {
final String? uuid;
String modelName;
final List<SubspaceTemplateModel>? subspaceModels;
List<SubspaceTemplateModel>? subspaceModels;
final List<TagModel>? tags;
String internalId;

View File

@ -4,7 +4,7 @@ class SubspaceTemplateModel {
final String? uuid;
String subspaceName;
final bool disabled;
final List<TagModel>? tags;
List<TagModel>? tags;
SubspaceTemplateModel({
this.uuid,

View File

@ -7,8 +7,8 @@ import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_spac
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_state.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
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/pages/spaces_management/space_model/models/tag_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
@ -27,9 +27,10 @@ class CreateSpaceModelDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
List<SubspaceTemplateModel>? subspaces = [];
final TextEditingController spaceNameController = TextEditingController();
List<SubspaceTemplateModel>? subspaces = spaceModel?.subspaceModels ?? [];
final TextEditingController spaceNameController = TextEditingController(
text: spaceModel?.modelName ?? '',
);
return AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
backgroundColor: ColorsManager.whiteColors,
@ -38,7 +39,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
child: BlocProvider(
create: (_) {
final bloc = CreateSpaceModelBloc();
if (spaceModel != null) {
if (spaceModel != null) {
bloc.add(UpdateSpaceTemplate(spaceModel!));
} else {
bloc.add(UpdateSpaceTemplate(SpaceTemplateModel(
@ -86,28 +87,13 @@ class CreateSpaceModelDialog extends StatelessWidget {
const SizedBox(height: 16),
SubspaceModelCreate(context, subspaces: subspaces),
const SizedBox(height: 10),
TextButton(
onPressed: () async {
final result = await showDialog<bool>(
barrierDismissible: false,
context: context,
builder: (context) => AddDeviceTypeModelWidget(
products: products,
subspaces: subspaces,
allTags: allTags,
spaceName: spaceNameController.text,
),
);
if (result == true) {}
},
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
),
child: const ButtonContentWidget(
icon: Icons.add,
label: 'Add Devices',
),
),
TagChipDisplay(context,
screenWidth: screenWidth,
spaceModel: spaceModel,
products: products,
subspaces: subspaces,
allTags: allTags,
spaceNameController: spaceNameController),
const SizedBox(height: 20),
SizedBox(
width: screenWidth * 0.25,

View File

@ -54,20 +54,20 @@ class SubspaceModelCreate extends StatelessWidget {
),
)
: SizedBox(
width: screenWidth * 0.25, // Set the desired width
width: screenWidth * 0.25,
child: Container(
padding: const EdgeInsets.all(8.0), // Add padding
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: ColorsManager.textFieldGreyColor, // Background color
borderRadius: BorderRadius.circular(15), // Rounded corners
color: ColorsManager.textFieldGreyColor,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: ColorsManager.textFieldGreyColor, // Border color
color: ColorsManager.textFieldGreyColor,
width: 3.0, // Border width
),
),
child: Wrap(
spacing: 8.0, // Spacing between chips
runSpacing: 8.0, // Spacing between rows of chips
spacing: 8.0,
runSpacing: 8.0,
children: [
...subspaces.map(
(subspace) => Chip(

View File

@ -0,0 +1,151 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart';
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';
class TagChipDisplay extends StatelessWidget {
final double screenWidth;
final SpaceTemplateModel? spaceModel;
final List<ProductModel>? products;
final List<SubspaceTemplateModel>? subspaces;
final List<String>? allTags;
final TextEditingController spaceNameController;
const TagChipDisplay(
BuildContext context, {
Key? key,
required this.screenWidth,
required this.spaceModel,
required this.products,
required this.subspaces,
required this.allTags,
required this.spaceNameController,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return (spaceModel?.subspaceModels?.isNotEmpty == true || 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
..._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/default_icon.svg', // Provide a default asset path if null
fit: BoxFit.contain,
),
),
label: Text(
'x${entry.value}', // Show count
style: const TextStyle(
color: ColorsManager.spaceColor,
),
),
backgroundColor:
Colors.white, // Chip background color
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(16), // Rounded chip
side: const BorderSide(
color: ColorsManager.spaceColor, // Border color
),
),
),
),
GestureDetector(
onTap: () async {
await showDialog<bool>(
barrierDismissible: false,
context: context,
builder: (context) => AddDeviceTypeModelWidget(
products: products,
subspaces: subspaces,
allTags: allTags,
spaceName: spaceNameController.text,
),
);
// Edit action
},
child: Chip(
label: const Text(
'Edit',
style: TextStyle(
color: ColorsManager.spaceColor), // Text color
),
backgroundColor:
Colors.white, // Background color for "Edit"
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16), // Rounded chip
side: const BorderSide(
color: ColorsManager.spaceColor), // Border color
),
),
),
],
),
),
)
: TextButton(
onPressed: () async {
final result = await showDialog<bool>(
barrierDismissible: false,
context: context,
builder: (context) => AddDeviceTypeModelWidget(
products: products,
subspaces: subspaces,
allTags: allTags,
spaceName: spaceNameController.text,
),
);
if (result == true) {}
},
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
),
child: const ButtonContentWidget(
icon: Icons.add,
label: 'Add Devices',
),
);
}
Map<ProductModel, int> _groupTags(List<TagModel> tags) {
final Map<ProductModel, int> groupedTags = {};
for (var tag in tags) {
if (tag.product != null) {
groupedTags[tag.product!] = (groupedTags[tag.product!] ?? 0) + 1;
}
}
return groupedTags;
}
}