mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
added tag model assignment ui
This commit is contained in:
@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,29 +1,20 @@
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
|
||||
class TagModel {
|
||||
final String uuid;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
final String tag;
|
||||
final bool disabled;
|
||||
String? uuid;
|
||||
String tag;
|
||||
final ProductModel? product;
|
||||
|
||||
TagModel({
|
||||
required this.uuid,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
this.uuid,
|
||||
required this.tag,
|
||||
required this.disabled,
|
||||
this.product,
|
||||
});
|
||||
|
||||
factory TagModel.fromJson(Map<String, dynamic> json) {
|
||||
return TagModel(
|
||||
uuid: json['uuid'] ?? '',
|
||||
createdAt: DateTime.parse(json['createdAt']),
|
||||
updatedAt: DateTime.parse(json['updatedAt']),
|
||||
tag: json['tag'] ?? '',
|
||||
disabled: json['disabled'] ?? false,
|
||||
product: json['product'] != null
|
||||
? ProductModel.fromMap(json['product'])
|
||||
: null,
|
||||
@ -33,10 +24,7 @@ class TagModel {
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
'updatedAt': updatedAt.toIso8601String(),
|
||||
'tag': tag,
|
||||
'disabled': disabled,
|
||||
'product': product?.toMap(),
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
||||
@ -31,56 +32,61 @@ class AddDeviceTypeModelWidget extends StatelessWidget {
|
||||
: 3;
|
||||
|
||||
return BlocProvider(
|
||||
create: (_) => AddDeviceTypeModelBloc(initialSelectedProducts ?? []),
|
||||
child: AlertDialog(
|
||||
title: const Text('Add Devices'),
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
content: SingleChildScrollView(
|
||||
child: Container(
|
||||
width: size.width * 0.9,
|
||||
height: size.height * 0.65,
|
||||
color: ColorsManager.textFieldGreyColor,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: ScrollableGridViewWidget(
|
||||
products: products, crossAxisCount: crossAxisCount),
|
||||
),
|
||||
create: (_) => AddDeviceTypeModelBloc(initialSelectedProducts ?? []),
|
||||
child: Builder(
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Add Devices'),
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
content: SingleChildScrollView(
|
||||
child: Container(
|
||||
width: size.width * 0.9,
|
||||
height: size.height * 0.65,
|
||||
color: ColorsManager.textFieldGreyColor,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: ScrollableGridViewWidget(
|
||||
products: products, crossAxisCount: crossAxisCount),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ActionButton(
|
||||
label: 'Cancel',
|
||||
backgroundColor: ColorsManager.boxColor,
|
||||
foregroundColor: ColorsManager.blackColor,
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ActionButton(
|
||||
label: 'Continue',
|
||||
backgroundColor: ColorsManager.secondaryColor,
|
||||
foregroundColor: ColorsManager.whiteColors,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
if (onProductsSelected != null) {
|
||||
final selectedProducts =
|
||||
context.read<AddDeviceTypeModelBloc>().state;
|
||||
onProductsSelected!(selectedProducts);
|
||||
}
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ActionButton(
|
||||
label: 'Cancel',
|
||||
backgroundColor: ColorsManager.boxColor,
|
||||
foregroundColor: ColorsManager.blackColor,
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ActionButton(
|
||||
label: 'Continue',
|
||||
backgroundColor: ColorsManager.secondaryColor,
|
||||
foregroundColor: ColorsManager.whiteColors,
|
||||
onPressed: () async {
|
||||
print(products);
|
||||
print("dfsdf");
|
||||
await showDialog<bool>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => AssignTagModelsDialog(
|
||||
products: products,
|
||||
subspaces: subspaces,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user