Compare commits

..

4 Commits

Author SHA1 Message Date
9091af2661 fixed text style 2025-01-28 13:27:05 +04:00
4b7f4d4279 fixed calculating products on add another device 2025-01-28 11:39:34 +04:00
e61cfd7e49 added option to update subspace 2025-01-28 10:48:14 +04:00
788fb75a68 fixed UI alignment 2025-01-27 18:12:57 +04:00
7 changed files with 249 additions and 88 deletions

View File

@ -26,7 +26,7 @@ class EditChip extends StatelessWidget {
child: Chip( child: Chip(
label: Text( label: Text(
label, label,
style: TextStyle(color: labelColor), style: Theme.of(context).textTheme.bodySmall!.copyWith(color: labelColor)
), ),
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(

View File

@ -149,50 +149,53 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
TextField( SizedBox(
controller: nameController, width: screenWidth * 0.25,
onChanged: (value) { child: TextField(
enteredName = value.trim(); controller: nameController,
setState(() { onChanged: (value) {
isNameFieldExist = false; enteredName = value.trim();
isOkButtonEnabled = false; setState(() {
isNameFieldInvalid = value.isEmpty; isNameFieldExist = false;
isOkButtonEnabled = false;
isNameFieldInvalid = value.isEmpty;
if (!isNameFieldInvalid) { if (!isNameFieldInvalid) {
if (_isNameConflict(value)) { if (_isNameConflict(value)) {
isNameFieldExist = true; isNameFieldExist = true;
isOkButtonEnabled = false; isOkButtonEnabled = false;
} else { } else {
isNameFieldExist = false; isNameFieldExist = false;
isOkButtonEnabled = true; isOkButtonEnabled = true;
}
} }
} });
}); },
}, style: const TextStyle(color: Colors.black),
style: const TextStyle(color: Colors.black), decoration: InputDecoration(
decoration: InputDecoration( hintText: 'Please enter the name',
hintText: 'Please enter the name', hintStyle: const TextStyle(
hintStyle: const TextStyle( fontSize: 14,
fontSize: 14, color: ColorsManager.lightGrayColor,
color: ColorsManager.lightGrayColor, fontWeight: FontWeight.w400,
fontWeight: FontWeight.w400,
),
filled: true,
fillColor: ColorsManager.boxColor,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: isNameFieldInvalid || isNameFieldExist
? ColorsManager.red
: ColorsManager.boxColor,
width: 1.5,
), ),
), filled: true,
focusedBorder: OutlineInputBorder( fillColor: ColorsManager.boxColor,
borderRadius: BorderRadius.circular(10), enabledBorder: OutlineInputBorder(
borderSide: const BorderSide( borderRadius: BorderRadius.circular(10),
color: ColorsManager.boxColor, borderSide: BorderSide(
width: 1.5, color: isNameFieldInvalid || isNameFieldExist
? ColorsManager.red
: ColorsManager.boxColor,
width: 1.5,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: ColorsManager.boxColor,
width: 1.5,
),
), ),
), ),
), ),
@ -222,6 +225,9 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
const SizedBox(height: 10), const SizedBox(height: 10),
selectedSpaceModel == null selectedSpaceModel == null
? TextButton( ? TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
),
onPressed: () { onPressed: () {
_showLinkSpaceModelDialog(context); _showLinkSpaceModelDialog(context);
}, },
@ -309,6 +315,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
subspaces == null subspaces == null
? TextButton( ? TextButton(
style: TextButton.styleFrom( style: TextButton.styleFrom(
padding: EdgeInsets.zero,
overlayColor: ColorsManager.transparentColor, overlayColor: ColorsManager.transparentColor,
), ),
onPressed: () async { onPressed: () async {
@ -337,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,

View File

@ -15,6 +15,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/tag_model/views/add_device_type_model_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'; import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
class AssignTagModelsDialog extends StatelessWidget { class AssignTagModelsDialog extends StatelessWidget {
final List<ProductModel>? products; final List<ProductModel>? products;
@ -258,7 +259,6 @@ class AssignTagModelsDialog extends StatelessWidget {
final processedTags = final processedTags =
result['updatedTags'] as List<TagModel>; result['updatedTags'] as List<TagModel>;
final processedSubspaces = result['subspaces']; final processedSubspaces = result['subspaces'];
if (context.mounted) { if (context.mounted) {
Navigator.of(context).pop(); Navigator.of(context).pop();
@ -270,8 +270,10 @@ class AssignTagModelsDialog extends StatelessWidget {
products: products, products: products,
subspaces: subspaces, subspaces: subspaces,
isCreate: false, isCreate: false,
initialSelectedProducts: initialSelectedProducts: TagHelper
addedProducts, .createInitialSelectedProducts(
processedTags,
processedSubspaces),
allTags: allTags, allTags: allTags,
spaceName: spaceName, spaceName: spaceName,
otherSpaceModels: otherSpaceModels, otherSpaceModels: otherSpaceModels,

View File

@ -102,14 +102,19 @@ class CreateSpaceModelDialog extends StatelessWidget {
name: value, name: value,
allModels: otherSpaceModels ?? [])); allModels: otherSpaceModels ?? []));
}, },
style: const TextStyle(color: ColorsManager.blackColor), style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: ColorsManager.blackColor),
decoration: InputDecoration( decoration: InputDecoration(
filled: true, filled: true,
fillColor: ColorsManager.textFieldGreyColor, fillColor: ColorsManager.textFieldGreyColor,
hintText: 'Please enter the name', hintText: 'Please enter the name',
errorText: state.errorMessage, errorText: state.errorMessage,
hintStyle: const TextStyle( hintStyle: Theme.of(context)
color: ColorsManager.lightGrayColor), .textTheme
.bodySmall!
.copyWith(color: ColorsManager.lightGrayColor),
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none, borderSide: BorderSide.none,
@ -123,7 +128,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
@ -160,7 +164,9 @@ class CreateSpaceModelDialog extends StatelessWidget {
const SizedBox(width: 10), const SizedBox(width: 10),
Expanded( Expanded(
child: DefaultButton( child: DefaultButton(
onPressed: (state.errorMessage == null) onPressed: ((state.errorMessage != null &&
state.errorMessage != '') ||
!isNameValid)
? () { ? () {
final updatedSpaceTemplate = final updatedSpaceTemplate =
updatedSpaceModel.copyWith( updatedSpaceModel.copyWith(
@ -238,8 +244,9 @@ class CreateSpaceModelDialog extends StatelessWidget {
: null, : null,
backgroundColor: ColorsManager.secondaryColor, backgroundColor: ColorsManager.secondaryColor,
borderRadius: 10, borderRadius: 10,
foregroundColor: (state.errorMessage != null && foregroundColor: ((state.errorMessage != null &&
state.errorMessage != '') state.errorMessage != '') ||
!isNameValid)
? ColorsManager.whiteColorsWithOpacity ? ColorsManager.whiteColorsWithOpacity
: ColorsManager.whiteColors, : ColorsManager.whiteColors,
child: const Text('OK'), child: const Text('OK'),
@ -253,7 +260,10 @@ class CreateSpaceModelDialog extends StatelessWidget {
} else if (state is CreateSpaceModelError) { } else if (state is CreateSpaceModelError) {
return Text( return Text(
'Error: ${state.message}', 'Error: ${state.message}',
style: const TextStyle(color: ColorsManager.warningRed), style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: ColorsManager.warningRed),
); );
} }

View File

@ -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);
}
}, },
); );
}, },

View File

@ -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: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: ColorsManager.warningRed),
),
),
],
); );
} }
} }

View File

@ -73,9 +73,12 @@ class TagChipDisplay extends StatelessWidget {
), ),
label: Text( label: Text(
'x${entry.value}', // Show count 'x${entry.value}', // Show count
style: const TextStyle( style: Theme.of(context)
color: ColorsManager.spaceColor, .textTheme
), .bodySmall!
.copyWith(
color:
ColorsManager.spaceColor),
), ),
backgroundColor: ColorsManager.whiteColors, backgroundColor: ColorsManager.whiteColors,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(