added tag model assignment ui

This commit is contained in:
hannathkadher
2025-01-05 19:56:39 +04:00
parent e44c3ae796
commit 5bd257ee56
3 changed files with 181 additions and 61 deletions

View File

@ -0,0 +1,126 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_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/utils/color_manager.dart';
class AssignTagModelsDialog extends StatefulWidget {
final List<ProductModel>? products;
final List<SubspaceTemplateModel>? subspaces;
final List<TagModel>? initialTags;
final ValueChanged<List<TagModel>>? onTagsAssigned;
const AssignTagModelsDialog({
Key? key,
required this.products,
required this.subspaces,
this.initialTags,
this.onTagsAssigned,
}) : super(key: key);
@override
AssignTagModelsDialogState createState() => AssignTagModelsDialogState();
}
class AssignTagModelsDialogState extends State<AssignTagModelsDialog> {
late List<TagModel> tags;
@override
void initState() {
super.initState();
if (widget.products != null) {
print(widget.products);
tags = [];
}
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Assign Tags'),
backgroundColor: ColorsManager.whiteColors,
content: SingleChildScrollView(
child: Container(
width: MediaQuery.of(context).size.width * 0.9,
child: DataTable(
columns: const [
DataColumn(label: Text('#')),
DataColumn(label: Text('Device')),
DataColumn(label: Text('Tag')),
DataColumn(label: Text('Location')),
],
rows: tags.asMap().entries.map((entry) {
final index = entry.key + 1;
final tagModel = entry.value;
return DataRow(cells: [
DataCell(Text(index.toString())),
DataCell(Text(tagModel.product?.name ?? 'Unknown')),
DataCell(
DropdownButton<String>(
value: tagModel.tag,
onChanged: (value) {
setState(() {
tagModel.tag = value!;
});
},
items: List.generate(10, (index) {
final tag = 'Tag ${index + 1}';
return DropdownMenuItem(value: tag, child: Text(tag));
}),
),
),
DataCell(
DropdownButton<String>(
value: widget.subspaces
?.firstWhere(
(subspace) =>
subspace.subspaceName == 'ssdsdf',
)
.subspaceName ??
'None',
onChanged: (value) {},
items: widget.subspaces!
.map((subspace) => DropdownMenuItem(
value: subspace.subspaceName,
child: Text(subspace.subspaceName),
))
.toList(),
),
),
]);
}).toList(),
),
),
),
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Back'),
style: ElevatedButton.styleFrom(
backgroundColor: ColorsManager.boxColor,
foregroundColor: ColorsManager.blackColor,
),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
if (widget.onTagsAssigned != null) {
widget.onTagsAssigned!(tags);
}
},
child: const Text('Save'),
style: ElevatedButton.styleFrom(
backgroundColor: ColorsManager.secondaryColor,
foregroundColor: ColorsManager.whiteColors,
),
),
],
),
],
);
}
}