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