mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 16:14:55 +00:00
cleaned subspace model create
This commit is contained in:
@ -2,38 +2,24 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
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/create_subspace_model/bloc/subspace_model_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_state.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_state.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_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';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart';
|
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
class CreateSubSpaceModelDialog extends StatelessWidget {
|
class CreateSubSpaceModelDialog extends StatelessWidget {
|
||||||
final bool isEdit;
|
final bool isEdit;
|
||||||
final String dialogTitle;
|
final String dialogTitle;
|
||||||
final List<SubspaceTemplateModel>? existingSubSpaces;
|
final List<SubspaceTemplateModel>? existingSubSpaces;
|
||||||
final String? spaceName;
|
final void Function(List<SubspaceTemplateModel> newSubspaces)? onUpdate;
|
||||||
final List<TagModel>? spaceTagModels;
|
|
||||||
final List<String>? allTags;
|
|
||||||
final List<ProductModel>? products;
|
|
||||||
final SpaceTemplateModel? spaceModel;
|
|
||||||
final void Function(SpaceTemplateModel newModel)? onLoad;
|
|
||||||
|
|
||||||
const CreateSubSpaceModelDialog(
|
const CreateSubSpaceModelDialog(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
required this.isEdit,
|
required this.isEdit,
|
||||||
required this.dialogTitle,
|
required this.dialogTitle,
|
||||||
this.existingSubSpaces,
|
this.existingSubSpaces,
|
||||||
required this.allTags,
|
this.onUpdate})
|
||||||
required this.spaceName,
|
|
||||||
required this.spaceTagModels,
|
|
||||||
required this.products,
|
|
||||||
required this.spaceModel,
|
|
||||||
this.onLoad})
|
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -171,21 +157,6 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
|
|||||||
label: 'Cancel',
|
label: 'Cancel',
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
await showDialog(
|
|
||||||
barrierDismissible: false,
|
|
||||||
context: context,
|
|
||||||
builder: (context) =>
|
|
||||||
CreateSpaceModelDialog(
|
|
||||||
products: products,
|
|
||||||
allTags: allTags,
|
|
||||||
onLoad: onLoad,
|
|
||||||
spaceModel: SpaceTemplateModel(
|
|
||||||
modelName: spaceName ?? '',
|
|
||||||
subspaceModels: existingSubSpaces,
|
|
||||||
tags: spaceTagModels,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -198,22 +169,7 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
|
|||||||
.state
|
.state
|
||||||
.subSpaces;
|
.subSpaces;
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
onUpdate!(subSpaces);
|
||||||
await showDialog(
|
|
||||||
barrierDismissible: false,
|
|
||||||
context: context,
|
|
||||||
builder: (context) =>
|
|
||||||
CreateSpaceModelDialog(
|
|
||||||
products: products,
|
|
||||||
allTags: allTags,
|
|
||||||
onLoad: onLoad,
|
|
||||||
spaceModel: SpaceTemplateModel(
|
|
||||||
modelName: spaceName ?? '',
|
|
||||||
subspaceModels: subSpaces,
|
|
||||||
tags: spaceTagModels,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
backgroundColor: ColorsManager.secondaryColor,
|
backgroundColor: ColorsManager.secondaryColor,
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
|
|||||||
@ -108,14 +108,15 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
SubspaceModelCreate(context,
|
SubspaceModelCreate(
|
||||||
subspaces: state.space.subspaceModels ?? [],
|
context,
|
||||||
onLoad:onLoad,
|
subspaces: state.space.subspaceModels ?? [],
|
||||||
allTags: allTags,
|
onSpaceModelUpdate: (updatedSubspaces) {
|
||||||
products: products,
|
context
|
||||||
spaceModel: spaceModel,
|
.read<CreateSpaceModelBloc>()
|
||||||
spaceTagModels: spaceModel?.tags ?? [],
|
.add(AddSubspacesToSpaceTemplate(updatedSubspaces));
|
||||||
spaceNameController: spaceNameController,),
|
},
|
||||||
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
TagChipDisplay(context,
|
TagChipDisplay(context,
|
||||||
screenWidth: screenWidth,
|
screenWidth: screenWidth,
|
||||||
|
|||||||
@ -1,30 +1,16 @@
|
|||||||
import 'package:flutter/material.dart';
|
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/space_template_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';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_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/button_content_widget.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/views/create_subspace_model_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/views/create_subspace_model_dialog.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
class SubspaceModelCreate extends StatelessWidget {
|
class SubspaceModelCreate extends StatelessWidget {
|
||||||
final List<SubspaceTemplateModel> subspaces;
|
final List<SubspaceTemplateModel> subspaces;
|
||||||
final TextEditingController spaceNameController;
|
final void Function(List<SubspaceTemplateModel> newSubspaces)?
|
||||||
final List<TagModel>? spaceTagModels;
|
onSpaceModelUpdate;
|
||||||
final List<String>? allTags;
|
|
||||||
final List<ProductModel>? products;
|
|
||||||
final SpaceTemplateModel? spaceModel;
|
|
||||||
final void Function(SpaceTemplateModel newModel)? onLoad;
|
|
||||||
|
|
||||||
const SubspaceModelCreate(BuildContext context,
|
const SubspaceModelCreate(BuildContext context,
|
||||||
{Key? key,
|
{Key? key, required this.subspaces, this.onSpaceModelUpdate})
|
||||||
required this.subspaces,
|
|
||||||
this.spaceTagModels,
|
|
||||||
required this.allTags,
|
|
||||||
required this.products,
|
|
||||||
required this.spaceModel,
|
|
||||||
required this.spaceNameController,
|
|
||||||
this.onLoad})
|
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -37,27 +23,7 @@ class SubspaceModelCreate extends StatelessWidget {
|
|||||||
overlayColor: ColorsManager.transparentColor,
|
overlayColor: ColorsManager.transparentColor,
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
Navigator.of(context).pop();
|
await _openDialog(context, 'Create Sub-space');
|
||||||
|
|
||||||
await showDialog<List<SubspaceTemplateModel>>(
|
|
||||||
barrierDismissible: false,
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return CreateSubSpaceModelDialog(
|
|
||||||
allTags: allTags,
|
|
||||||
spaceName: spaceNameController.text,
|
|
||||||
spaceModel: spaceModel,
|
|
||||||
spaceTagModels: spaceTagModels,
|
|
||||||
products: products,
|
|
||||||
isEdit: true,
|
|
||||||
dialogTitle: subspaces.isEmpty
|
|
||||||
? 'Create Sub-space'
|
|
||||||
: 'Edit Sub-space',
|
|
||||||
existingSubSpaces: subspaces,
|
|
||||||
onLoad: onLoad,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
child: const ButtonContentWidget(
|
child: const ButtonContentWidget(
|
||||||
icon: Icons.add,
|
icon: Icons.add,
|
||||||
@ -99,24 +65,7 @@ class SubspaceModelCreate extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
Navigator.of(context).pop();
|
await _openDialog(context, 'Edit Sub-space');
|
||||||
await showDialog<List<SubspaceTemplateModel>>(
|
|
||||||
barrierDismissible: false,
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return CreateSubSpaceModelDialog(
|
|
||||||
isEdit: true,
|
|
||||||
dialogTitle: 'Edit Sub-space',
|
|
||||||
existingSubSpaces: subspaces,
|
|
||||||
allTags: allTags,
|
|
||||||
spaceName: spaceNameController.text,
|
|
||||||
spaceTagModels: spaceTagModels,
|
|
||||||
products: products,
|
|
||||||
spaceModel: spaceModel,
|
|
||||||
onLoad: onLoad,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
child: Chip(
|
child: Chip(
|
||||||
label: const Text(
|
label: const Text(
|
||||||
@ -137,4 +86,21 @@ class SubspaceModelCreate extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _openDialog(BuildContext context, String dialogTitle) async {
|
||||||
|
await showDialog(
|
||||||
|
barrierDismissible: false,
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return CreateSubSpaceModelDialog(
|
||||||
|
isEdit: true,
|
||||||
|
dialogTitle: dialogTitle,
|
||||||
|
existingSubSpaces: subspaces,
|
||||||
|
onUpdate: (subspaceModels) {
|
||||||
|
onSpaceModelUpdate!(subspaceModels);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user