mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
separation of widget
This commit is contained in:
@ -5,11 +5,11 @@ 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/widgets/add_device_type_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_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/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/subspace_model_create_widget.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class CreateSpaceModelDialog extends StatelessWidget {
|
||||
@ -67,7 +67,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildSubspacesSection(context, subspaces),
|
||||
SubspaceModelCreate(context, subspaces: subspaces),
|
||||
const SizedBox(height: 10),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
@ -125,124 +125,4 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSubspacesSection(
|
||||
BuildContext context, List<SubspaceTemplateModel> subspaces) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
return Container(
|
||||
child: subspaces.isEmpty
|
||||
? TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
overlayColor: Colors.transparent,
|
||||
),
|
||||
onPressed: () async {
|
||||
final result = await showDialog<List<SubspaceTemplateModel>>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CreateSubSpaceModelDialog(
|
||||
isEdit: true,
|
||||
dialogTitle: subspaces.isEmpty
|
||||
? 'Create Sub-space'
|
||||
: 'Edit Sub-space',
|
||||
existingSubSpaces: subspaces,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
subspaces.clear();
|
||||
subspaces.addAll(result);
|
||||
context
|
||||
.read<CreateSpaceModelBloc>()
|
||||
.add(AddSubspacesToSpaceTemplate(subspaces));
|
||||
}
|
||||
},
|
||||
child: const ButtonContentWidget(
|
||||
icon: Icons.add,
|
||||
label: 'Create Sub Space',
|
||||
),
|
||||
)
|
||||
: SizedBox(
|
||||
width: screenWidth * 0.25, // Set the desired width
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(
|
||||
8.0), // Add padding around the content
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.textFieldGreyColor, // Background color
|
||||
borderRadius: BorderRadius.circular(15), // Rounded corners
|
||||
border: Border.all(
|
||||
color: ColorsManager.textFieldGreyColor, // Border color
|
||||
width: 3.0, // Border width
|
||||
),
|
||||
),
|
||||
child: Wrap(
|
||||
spacing: 8.0, // Spacing between chips
|
||||
runSpacing: 8.0, // Spacing between rows of chips
|
||||
children: [
|
||||
...subspaces.map(
|
||||
(subspace) => Chip(
|
||||
label: Text(
|
||||
subspace.subspaceName,
|
||||
style: const TextStyle(
|
||||
color: ColorsManager.spaceColor), // Text color
|
||||
),
|
||||
backgroundColor:
|
||||
Colors.white, // Chip background color
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(16), // Rounded chip
|
||||
side: const BorderSide(
|
||||
color:
|
||||
ColorsManager.spaceColor), // Border color
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final result =
|
||||
await showDialog<List<SubspaceTemplateModel>>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CreateSubSpaceModelDialog(
|
||||
isEdit: true,
|
||||
dialogTitle: 'Edit Sub-space',
|
||||
existingSubSpaces: subspaces,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
subspaces.clear();
|
||||
subspaces.addAll(result);
|
||||
context
|
||||
.read<CreateSpaceModelBloc>()
|
||||
.add(AddSubspacesToSpaceTemplate(subspaces));
|
||||
}
|
||||
},
|
||||
child: Chip(
|
||||
label: const Text(
|
||||
'Edit',
|
||||
style: TextStyle(
|
||||
color: ColorsManager
|
||||
.spaceColor), // Text color for "Edit"
|
||||
),
|
||||
backgroundColor:
|
||||
Colors.white, // Background color for "Edit"
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(16), // Rounded chip
|
||||
side: const BorderSide(
|
||||
color:
|
||||
ColorsManager.spaceColor), // Border color
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,133 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.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/models/space_template_model.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart';
|
||||
|
||||
class SubspaceModelCreate extends StatelessWidget {
|
||||
final List<SubspaceTemplateModel> subspaces;
|
||||
|
||||
const SubspaceModelCreate(BuildContext context, {
|
||||
Key? key,
|
||||
required this.subspaces,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
return Container(
|
||||
child: subspaces.isEmpty
|
||||
? TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
overlayColor: ColorsManager.transparentColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
final result = await showDialog<List<SubspaceTemplateModel>>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CreateSubSpaceModelDialog(
|
||||
isEdit: true,
|
||||
dialogTitle: subspaces.isEmpty
|
||||
? 'Create Sub-space'
|
||||
: 'Edit Sub-space',
|
||||
existingSubSpaces: subspaces,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
subspaces.clear();
|
||||
subspaces.addAll(result);
|
||||
context
|
||||
.read<CreateSpaceModelBloc>()
|
||||
.add(AddSubspacesToSpaceTemplate(subspaces));
|
||||
}
|
||||
},
|
||||
child: const ButtonContentWidget(
|
||||
icon: Icons.add,
|
||||
label: 'Create Sub Space',
|
||||
),
|
||||
)
|
||||
: SizedBox(
|
||||
width: screenWidth * 0.25, // Set the desired width
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8.0), // Add padding
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.textFieldGreyColor, // Background color
|
||||
borderRadius: BorderRadius.circular(15), // Rounded corners
|
||||
border: Border.all(
|
||||
color: ColorsManager.textFieldGreyColor, // Border color
|
||||
width: 3.0, // Border width
|
||||
),
|
||||
),
|
||||
child: Wrap(
|
||||
spacing: 8.0, // Spacing between chips
|
||||
runSpacing: 8.0, // Spacing between rows of chips
|
||||
children: [
|
||||
...subspaces.map(
|
||||
(subspace) => Chip(
|
||||
label: Text(
|
||||
subspace.subspaceName,
|
||||
style: const TextStyle(
|
||||
color: ColorsManager.spaceColor), // Text color
|
||||
),
|
||||
backgroundColor: Colors.white, // Chip background color
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(16), // Rounded chip
|
||||
side: const BorderSide(
|
||||
color: ColorsManager.spaceColor), // Border color
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final result =
|
||||
await showDialog<List<SubspaceTemplateModel>>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CreateSubSpaceModelDialog(
|
||||
isEdit: true,
|
||||
dialogTitle: 'Edit Sub-space',
|
||||
existingSubSpaces: subspaces,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
subspaces.clear();
|
||||
subspaces.addAll(result);
|
||||
context
|
||||
.read<CreateSpaceModelBloc>()
|
||||
.add(AddSubspacesToSpaceTemplate(subspaces));
|
||||
}
|
||||
},
|
||||
child: Chip(
|
||||
label: const Text(
|
||||
'Edit',
|
||||
style: TextStyle(
|
||||
color: ColorsManager.spaceColor), // Text color
|
||||
),
|
||||
backgroundColor:
|
||||
Colors.white, // Background color for "Edit"
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(16), // Rounded chip
|
||||
side: const BorderSide(
|
||||
color: ColorsManager.spaceColor), // Border color
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user