mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
fixed issues in create space model
This commit is contained in:
@ -10,7 +10,7 @@ class SubSpaceModelBloc extends Bloc<SubSpaceModelEvent, SubSpaceModelState> {
|
|||||||
on<AddSubSpaceModel>((event, emit) {
|
on<AddSubSpaceModel>((event, emit) {
|
||||||
final updatedSubSpaces = List<SubspaceTemplateModel>.from(state.subSpaces)
|
final updatedSubSpaces = List<SubspaceTemplateModel>.from(state.subSpaces)
|
||||||
..add(event.subSpace);
|
..add(event.subSpace);
|
||||||
emit(SubSpaceModelState(updatedSubSpaces, []));
|
emit(SubSpaceModelState(updatedSubSpaces, state.updatedSubSpaceModels));
|
||||||
});
|
});
|
||||||
|
|
||||||
on<RemoveSubSpaceModel>((event, emit) {
|
on<RemoveSubSpaceModel>((event, emit) {
|
||||||
@ -30,5 +30,25 @@ class SubSpaceModelBloc extends Bloc<SubSpaceModelEvent, SubSpaceModelState> {
|
|||||||
|
|
||||||
emit(SubSpaceModelState(updatedSubSpaces, updatedSubspaceModels));
|
emit(SubSpaceModelState(updatedSubSpaces, updatedSubspaceModels));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
on<UpdateSubSpaceModel>((event, emit) {
|
||||||
|
final updatedSubSpaces = state.subSpaces.map((subSpace) {
|
||||||
|
if (subSpace.uuid == event.updatedSubSpace.uuid) {
|
||||||
|
return event.updatedSubSpace;
|
||||||
|
}
|
||||||
|
return subSpace;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
final updatedSubspaceModels = List<UpdateSubspaceTemplateModel>.from(
|
||||||
|
state.updatedSubSpaceModels,
|
||||||
|
);
|
||||||
|
|
||||||
|
updatedSubspaceModels.add(UpdateSubspaceTemplateModel(
|
||||||
|
action: Action.update,
|
||||||
|
uuid: event.updatedSubSpace.uuid!,
|
||||||
|
));
|
||||||
|
|
||||||
|
emit(SubSpaceModelState(updatedSubSpaces, updatedSubspaceModels));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
// Events
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||||
|
|
||||||
abstract class SubSpaceModelEvent {}
|
abstract class SubSpaceModelEvent {}
|
||||||
@ -12,3 +11,8 @@ class RemoveSubSpaceModel extends SubSpaceModelEvent {
|
|||||||
final SubspaceTemplateModel subSpace;
|
final SubspaceTemplateModel subSpace;
|
||||||
RemoveSubSpaceModel(this.subSpace);
|
RemoveSubSpaceModel(this.subSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UpdateSubSpaceModel extends SubSpaceModelEvent {
|
||||||
|
final SubspaceTemplateModel updatedSubSpace;
|
||||||
|
UpdateSubSpaceModel(this.updatedSubSpace);
|
||||||
|
}
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class ButtonContentWidget extends StatelessWidget {
|
||||||
|
final IconData icon;
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
const ButtonContentWidget({
|
||||||
|
Key? key,
|
||||||
|
required this.icon,
|
||||||
|
required this.label,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
width: screenWidth * 0.25,
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: ColorsManager.textFieldGreyColor,
|
||||||
|
border: Border.all(
|
||||||
|
color: ColorsManager.neutralGray,
|
||||||
|
width: 3.0,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
color: ColorsManager.spaceColor,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
label,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,8 @@ import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
|||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.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/widgets/add_device_type_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/add_device_type_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/button_content_widget.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/create_subspace_model_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/create_subspace_model_dialog.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
@ -14,6 +16,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
List<SubspaceTemplateModel>? subspaces = []; // Store subspaces here
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||||
@ -55,26 +58,28 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final result = await showDialog<String>(
|
final result = await showDialog<List<SubspaceTemplateModel>>(
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return const CreateSubSpaceModelDialog(
|
return CreateSubSpaceModelDialog(
|
||||||
isEdit: true,
|
isEdit: true,
|
||||||
dialogTitle: 'Create Sub-space',
|
dialogTitle: 'Create Sub-space',
|
||||||
|
existingSubSpaces: subspaces,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (result != null && result.isNotEmpty) {
|
|
||||||
// Handle the result if necessary
|
if (result != null) {
|
||||||
print('Subspace created: $result');
|
// Update the subspaces
|
||||||
|
subspaces = result;
|
||||||
|
print('Updated Subspaces: $subspaces');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
),
|
),
|
||||||
child: _buildButtonContent(
|
child: const ButtonContentWidget(
|
||||||
context,
|
|
||||||
icon: Icons.add,
|
icon: Icons.add,
|
||||||
label: 'Create Sub Space',
|
label: 'Create Sub Space',
|
||||||
),
|
),
|
||||||
@ -97,8 +102,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
),
|
),
|
||||||
child: _buildButtonContent(
|
child: ButtonContentWidget(
|
||||||
context,
|
|
||||||
icon: Icons.add,
|
icon: Icons.add,
|
||||||
label: 'Add Devices',
|
label: 'Add Devices',
|
||||||
),
|
),
|
||||||
@ -118,7 +122,8 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
// Return data when OK is pressed
|
||||||
|
Navigator.of(context).pop(subspaces);
|
||||||
},
|
},
|
||||||
backgroundColor: ColorsManager.secondaryColor,
|
backgroundColor: ColorsManager.secondaryColor,
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
@ -134,44 +139,4 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildButtonContent(BuildContext context,
|
|
||||||
{required IconData icon, required String label}) {
|
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
|
||||||
|
|
||||||
return SizedBox(
|
|
||||||
width: screenWidth * 0.25,
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: ColorsManager.textFieldGreyColor,
|
|
||||||
border: Border.all(
|
|
||||||
color: ColorsManager.neutralGray,
|
|
||||||
width: 3.0,
|
|
||||||
),
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
color: ColorsManager.spaceColor,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: ColorsManager.blackColor,
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,58 +8,32 @@ import 'package:syncrow_web/pages/spaces_management/space_model/bloc/subspace_mo
|
|||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
class CreateSubSpaceModelDialog extends StatefulWidget {
|
class CreateSubSpaceModelDialog extends StatelessWidget {
|
||||||
final bool isEdit;
|
final bool isEdit;
|
||||||
final String dialogTitle;
|
final String dialogTitle;
|
||||||
final List<SubspaceTemplateModel>? existingSubSpaces;
|
final List<SubspaceTemplateModel>? existingSubSpaces;
|
||||||
|
|
||||||
const CreateSubSpaceModelDialog({
|
const CreateSubSpaceModelDialog({
|
||||||
super.key,
|
Key? key,
|
||||||
required this.isEdit,
|
required this.isEdit,
|
||||||
required this.dialogTitle,
|
required this.dialogTitle,
|
||||||
this.existingSubSpaces,
|
this.existingSubSpaces,
|
||||||
});
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
|
||||||
_CreateSubSpaceModelDialogState createState() =>
|
|
||||||
_CreateSubSpaceModelDialogState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CreateSubSpaceModelDialogState extends State<CreateSubSpaceModelDialog> {
|
|
||||||
final TextEditingController textController = TextEditingController();
|
|
||||||
final FocusNode focusNode = FocusNode();
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
focusNode.requestFocus();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (widget.isEdit) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
textController.dispose();
|
|
||||||
focusNode.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
final textController = TextEditingController();
|
||||||
|
|
||||||
return Dialog(
|
return Dialog(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
),
|
),
|
||||||
|
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (_) {
|
create: (_) {
|
||||||
final bloc = SubSpaceModelBloc();
|
final bloc = SubSpaceModelBloc();
|
||||||
if (widget.existingSubSpaces != null) {
|
if (existingSubSpaces != null) {
|
||||||
for (var subSpace in widget.existingSubSpaces!) {
|
for (var subSpace in existingSubSpaces!) {
|
||||||
bloc.add(AddSubSpaceModel(subSpace));
|
bloc.add(AddSubSpaceModel(subSpace));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +50,7 @@ class _CreateSubSpaceModelDialogState extends State<CreateSubSpaceModelDialog> {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
widget.dialogTitle,
|
dialogTitle,
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.headlineLarge
|
.headlineLarge
|
||||||
@ -97,15 +71,18 @@ class _CreateSubSpaceModelDialogState extends State<CreateSubSpaceModelDialog> {
|
|||||||
children: [
|
children: [
|
||||||
...state.subSpaces.map(
|
...state.subSpaces.map(
|
||||||
(subSpace) => Chip(
|
(subSpace) => Chip(
|
||||||
label: Text(subSpace.subspaceName,
|
label: Text(
|
||||||
style: const TextStyle(
|
subSpace.subspaceName,
|
||||||
color: ColorsManager.spaceColor)),
|
style: const TextStyle(
|
||||||
|
color: ColorsManager.spaceColor),
|
||||||
|
),
|
||||||
backgroundColor: ColorsManager.whiteColors,
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
side: const BorderSide(
|
side: const BorderSide(
|
||||||
color: ColorsManager.transparentColor,
|
color: ColorsManager.transparentColor,
|
||||||
width: 0),
|
width: 0,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
deleteIcon: Container(
|
deleteIcon: Container(
|
||||||
width: 24,
|
width: 24,
|
||||||
@ -132,7 +109,6 @@ class _CreateSubSpaceModelDialogState extends State<CreateSubSpaceModelDialog> {
|
|||||||
width: 200,
|
width: 200,
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: textController,
|
controller: textController,
|
||||||
focusNode: focusNode,
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
hintText: state.subSpaces.isEmpty
|
hintText: state.subSpaces.isEmpty
|
||||||
@ -148,7 +124,6 @@ class _CreateSubSpaceModelDialogState extends State<CreateSubSpaceModelDialog> {
|
|||||||
subspaceName: value.trim(),
|
subspaceName: value.trim(),
|
||||||
disabled: false)));
|
disabled: false)));
|
||||||
textController.clear();
|
textController.clear();
|
||||||
focusNode.requestFocus();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
|
Reference in New Issue
Block a user