mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
added option to update subspace
This commit is contained in:
@ -344,10 +344,21 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
runSpacing: 8.0,
|
runSpacing: 8.0,
|
||||||
children: [
|
children: [
|
||||||
if (subspaces != null)
|
if (subspaces != null)
|
||||||
...subspaces!.map(
|
...subspaces!.map((subspace) =>
|
||||||
(subspace) => SubspaceNameDisplayWidget(
|
SubspaceNameDisplayWidget(
|
||||||
text: subspace.subspaceName,
|
validateName: (updatedName) {
|
||||||
)),
|
return !subspaces!.any((s) =>
|
||||||
|
s != subspace &&
|
||||||
|
s.subspaceName == updatedName);
|
||||||
|
},
|
||||||
|
text: subspace.subspaceName,
|
||||||
|
onNameChanged: (updatedName) {
|
||||||
|
setState(() {
|
||||||
|
subspace.subspaceName =
|
||||||
|
updatedName;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)),
|
||||||
EditChip(
|
EditChip(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_showSubSpaceDialog(context, enteredName,
|
_showSubSpaceDialog(context, enteredName,
|
||||||
|
@ -123,7 +123,6 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
SubspaceModelCreate(
|
SubspaceModelCreate(
|
||||||
context,
|
|
||||||
subspaces: state.space.subspaceModels ?? [],
|
subspaces: state.space.subspaceModels ?? [],
|
||||||
onSpaceModelUpdate: (updatedSubspaces) {
|
onSpaceModelUpdate: (updatedSubspaces) {
|
||||||
context
|
context
|
||||||
|
@ -6,20 +6,36 @@ import 'package:syncrow_web/pages/spaces_management/create_subspace_model/views/
|
|||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/subspace_name_label_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/subspace_name_label_widget.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
class SubspaceModelCreate extends StatelessWidget {
|
class SubspaceModelCreate extends StatefulWidget {
|
||||||
final List<SubspaceTemplateModel> subspaces;
|
final List<SubspaceTemplateModel> subspaces;
|
||||||
final void Function(List<SubspaceTemplateModel> newSubspaces)?
|
final void Function(List<SubspaceTemplateModel> newSubspaces)?
|
||||||
onSpaceModelUpdate;
|
onSpaceModelUpdate;
|
||||||
|
|
||||||
const SubspaceModelCreate(BuildContext context,
|
const SubspaceModelCreate({
|
||||||
{Key? key, required this.subspaces, this.onSpaceModelUpdate})
|
Key? key,
|
||||||
: super(key: key);
|
required this.subspaces,
|
||||||
|
this.onSpaceModelUpdate,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SubspaceModelCreateState createState() => _SubspaceModelCreateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SubspaceModelCreateState extends State<SubspaceModelCreate> {
|
||||||
|
late List<SubspaceTemplateModel> _subspaces;
|
||||||
|
String? errorSubspaceId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_subspaces = List.from(widget.subspaces);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
return Container(
|
return Container(
|
||||||
child: subspaces.isEmpty
|
child: _subspaces.isEmpty
|
||||||
? TextButton(
|
? TextButton(
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
overlayColor: ColorsManager.transparentColor,
|
overlayColor: ColorsManager.transparentColor,
|
||||||
@ -41,16 +57,33 @@ class SubspaceModelCreate extends StatelessWidget {
|
|||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: ColorsManager.textFieldGreyColor,
|
color: ColorsManager.textFieldGreyColor,
|
||||||
width: 3.0, // Border width
|
width: 3.0,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
spacing: 8.0,
|
spacing: 8.0,
|
||||||
runSpacing: 8.0,
|
runSpacing: 8.0,
|
||||||
children: [
|
children: [
|
||||||
...subspaces.map((subspace) => SubspaceNameDisplayWidget(
|
..._subspaces.map((subspace) {
|
||||||
text: subspace.subspaceName,
|
return Column(
|
||||||
)),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
SubspaceNameDisplayWidget(
|
||||||
|
text: subspace.subspaceName,
|
||||||
|
validateName: (updatedName) {
|
||||||
|
return !_subspaces.any((s) =>
|
||||||
|
s != subspace &&
|
||||||
|
s.subspaceName == updatedName);
|
||||||
|
},
|
||||||
|
onNameChanged: (updatedName) {
|
||||||
|
setState(() {
|
||||||
|
subspace.subspaceName = updatedName;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}),
|
||||||
EditChip(
|
EditChip(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await _openDialog(context, 'Edit Sub-space');
|
await _openDialog(context, 'Edit Sub-space');
|
||||||
@ -71,9 +104,15 @@ class SubspaceModelCreate extends StatelessWidget {
|
|||||||
return CreateSubSpaceModelDialog(
|
return CreateSubSpaceModelDialog(
|
||||||
isEdit: true,
|
isEdit: true,
|
||||||
dialogTitle: dialogTitle,
|
dialogTitle: dialogTitle,
|
||||||
existingSubSpaces: subspaces,
|
existingSubSpaces: _subspaces,
|
||||||
onUpdate: (subspaceModels) {
|
onUpdate: (subspaceModels) {
|
||||||
onSpaceModelUpdate!(subspaceModels);
|
setState(() {
|
||||||
|
_subspaces = subspaceModels;
|
||||||
|
errorSubspaceId = null;
|
||||||
|
});
|
||||||
|
if (widget.onSpaceModelUpdate != null) {
|
||||||
|
widget.onSpaceModelUpdate!(subspaceModels);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
class SubspaceNameDisplayWidget extends StatelessWidget {
|
class SubspaceNameDisplayWidget extends StatefulWidget {
|
||||||
final String text;
|
final String text;
|
||||||
final TextStyle? textStyle;
|
final TextStyle? textStyle;
|
||||||
final Color backgroundColor;
|
final Color backgroundColor;
|
||||||
final Color borderColor;
|
final Color borderColor;
|
||||||
final EdgeInsetsGeometry padding;
|
final EdgeInsetsGeometry padding;
|
||||||
final BorderRadiusGeometry borderRadius;
|
final BorderRadiusGeometry borderRadius;
|
||||||
|
final void Function(String updatedName) onNameChanged;
|
||||||
|
final bool Function(String updatedName) validateName;
|
||||||
|
|
||||||
const SubspaceNameDisplayWidget({
|
const SubspaceNameDisplayWidget({
|
||||||
Key? key,
|
Key? key,
|
||||||
@ -17,25 +19,112 @@ class SubspaceNameDisplayWidget extends StatelessWidget {
|
|||||||
this.borderColor = ColorsManager.transparentColor,
|
this.borderColor = ColorsManager.transparentColor,
|
||||||
this.padding = const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
this.padding = const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
||||||
this.borderRadius = const BorderRadius.all(Radius.circular(10)),
|
this.borderRadius = const BorderRadius.all(Radius.circular(10)),
|
||||||
|
required this.onNameChanged,
|
||||||
|
required this.validateName,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SubspaceNameDisplayWidgetState createState() =>
|
||||||
|
_SubspaceNameDisplayWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SubspaceNameDisplayWidgetState extends State<SubspaceNameDisplayWidget> {
|
||||||
|
bool isEditing = false;
|
||||||
|
late TextEditingController _controller;
|
||||||
|
late FocusNode _focusNode;
|
||||||
|
late String previousName;
|
||||||
|
String? errorText;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller = TextEditingController(text: widget.text);
|
||||||
|
_focusNode = FocusNode();
|
||||||
|
previousName = widget.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
_focusNode.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleValidationAndSave() {
|
||||||
|
final updatedName = _controller.text;
|
||||||
|
if (widget.validateName(updatedName)) {
|
||||||
|
setState(() {
|
||||||
|
errorText = null;
|
||||||
|
isEditing = false;
|
||||||
|
previousName = updatedName;
|
||||||
|
widget.onNameChanged(updatedName);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
errorText = 'Subspace name already exists.';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Column(
|
||||||
padding: padding,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
decoration: BoxDecoration(
|
children: [
|
||||||
color: backgroundColor,
|
GestureDetector(
|
||||||
borderRadius: borderRadius,
|
onTap: () {
|
||||||
border: Border.all(color: borderColor),
|
setState(() {
|
||||||
),
|
isEditing = true;
|
||||||
child: Text(
|
_focusNode.requestFocus();
|
||||||
text,
|
});
|
||||||
style: textStyle ??
|
},
|
||||||
Theme.of(context)
|
child: Container(
|
||||||
.textTheme
|
padding: widget.padding,
|
||||||
.bodySmall
|
decoration: BoxDecoration(
|
||||||
?.copyWith(color: ColorsManager.spaceColor),
|
color: widget.backgroundColor,
|
||||||
),
|
borderRadius: widget.borderRadius,
|
||||||
|
border: Border.all(color: widget.borderColor),
|
||||||
|
),
|
||||||
|
child: isEditing
|
||||||
|
? TextField(
|
||||||
|
controller: _controller,
|
||||||
|
focusNode: _focusNode,
|
||||||
|
style: widget.textStyle ??
|
||||||
|
Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodySmall
|
||||||
|
?.copyWith(color: ColorsManager.spaceColor),
|
||||||
|
autofocus: true,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
border: InputBorder.none,
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
|
),
|
||||||
|
onSubmitted: (value) {
|
||||||
|
_handleValidationAndSave();
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: Text(
|
||||||
|
widget.text,
|
||||||
|
style: widget.textStyle ??
|
||||||
|
Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodySmall
|
||||||
|
?.copyWith(color: ColorsManager.spaceColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (errorText != null)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 4.0),
|
||||||
|
child: Text(
|
||||||
|
errorText!,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: ColorsManager.warningRed,
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user