mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +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:syncrow_web/pages/common/buttons/cancel_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_event.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/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';
|
||||
|
||||
class CreateSubSpaceModelDialog extends StatelessWidget {
|
||||
final bool isEdit;
|
||||
final String dialogTitle;
|
||||
final List<SubspaceTemplateModel>? existingSubSpaces;
|
||||
final String? spaceName;
|
||||
final List<TagModel>? spaceTagModels;
|
||||
final List<String>? allTags;
|
||||
final List<ProductModel>? products;
|
||||
final SpaceTemplateModel? spaceModel;
|
||||
final void Function(SpaceTemplateModel newModel)? onLoad;
|
||||
final void Function(List<SubspaceTemplateModel> newSubspaces)? onUpdate;
|
||||
|
||||
const CreateSubSpaceModelDialog(
|
||||
{Key? key,
|
||||
required this.isEdit,
|
||||
required this.dialogTitle,
|
||||
this.existingSubSpaces,
|
||||
required this.allTags,
|
||||
required this.spaceName,
|
||||
required this.spaceTagModels,
|
||||
required this.products,
|
||||
required this.spaceModel,
|
||||
this.onLoad})
|
||||
this.onUpdate})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@ -171,21 +157,6 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
|
||||
label: 'Cancel',
|
||||
onPressed: () async {
|
||||
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
|
||||
.subSpaces;
|
||||
Navigator.of(context).pop();
|
||||
|
||||
await showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
CreateSpaceModelDialog(
|
||||
products: products,
|
||||
allTags: allTags,
|
||||
onLoad: onLoad,
|
||||
spaceModel: SpaceTemplateModel(
|
||||
modelName: spaceName ?? '',
|
||||
subspaceModels: subSpaces,
|
||||
tags: spaceTagModels,
|
||||
),
|
||||
),
|
||||
);
|
||||
onUpdate!(subSpaces);
|
||||
},
|
||||
backgroundColor: ColorsManager.secondaryColor,
|
||||
borderRadius: 10,
|
||||
|
@ -108,14 +108,15 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SubspaceModelCreate(context,
|
||||
subspaces: state.space.subspaceModels ?? [],
|
||||
onLoad:onLoad,
|
||||
allTags: allTags,
|
||||
products: products,
|
||||
spaceModel: spaceModel,
|
||||
spaceTagModels: spaceModel?.tags ?? [],
|
||||
spaceNameController: spaceNameController,),
|
||||
SubspaceModelCreate(
|
||||
context,
|
||||
subspaces: state.space.subspaceModels ?? [],
|
||||
onSpaceModelUpdate: (updatedSubspaces) {
|
||||
context
|
||||
.read<CreateSpaceModelBloc>()
|
||||
.add(AddSubspacesToSpaceTemplate(updatedSubspaces));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
TagChipDisplay(context,
|
||||
screenWidth: screenWidth,
|
||||
|
@ -1,30 +1,16 @@
|
||||
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/tag_model.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/utils/color_manager.dart';
|
||||
|
||||
class SubspaceModelCreate extends StatelessWidget {
|
||||
final List<SubspaceTemplateModel> subspaces;
|
||||
final TextEditingController spaceNameController;
|
||||
final List<TagModel>? spaceTagModels;
|
||||
final List<String>? allTags;
|
||||
final List<ProductModel>? products;
|
||||
final SpaceTemplateModel? spaceModel;
|
||||
final void Function(SpaceTemplateModel newModel)? onLoad;
|
||||
final void Function(List<SubspaceTemplateModel> newSubspaces)?
|
||||
onSpaceModelUpdate;
|
||||
|
||||
const SubspaceModelCreate(BuildContext context,
|
||||
{Key? key,
|
||||
required this.subspaces,
|
||||
this.spaceTagModels,
|
||||
required this.allTags,
|
||||
required this.products,
|
||||
required this.spaceModel,
|
||||
required this.spaceNameController,
|
||||
this.onLoad})
|
||||
{Key? key, required this.subspaces, this.onSpaceModelUpdate})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@ -37,27 +23,7 @@ class SubspaceModelCreate extends StatelessWidget {
|
||||
overlayColor: ColorsManager.transparentColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
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,
|
||||
);
|
||||
},
|
||||
);
|
||||
await _openDialog(context, 'Create Sub-space');
|
||||
},
|
||||
child: const ButtonContentWidget(
|
||||
icon: Icons.add,
|
||||
@ -99,24 +65,7 @@ class SubspaceModelCreate extends StatelessWidget {
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
Navigator.of(context).pop();
|
||||
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,
|
||||
);
|
||||
},
|
||||
);
|
||||
await _openDialog(context, 'Edit Sub-space');
|
||||
},
|
||||
child: Chip(
|
||||
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