separate widget

This commit is contained in:
hannathkadher
2025-01-05 12:54:35 +04:00
parent 1c256cc55c
commit 819670867d
2 changed files with 101 additions and 33 deletions

View File

@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.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/models/space_template_model.dart';
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/space_model_card_widget.dart';
@ -36,7 +38,10 @@ class SpaceModelPage extends StatelessWidget {
showDialog(
context: context,
builder: (BuildContext context) {
return CreateSpaceModelDialog(products: products);
return BlocProvider<CreateSpaceModelBloc>(
create: (_) => CreateSpaceModelBloc(),
child: CreateSpaceModelDialog(products: products),
);
},
);
},

View File

@ -1,4 +1,5 @@
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';
@ -58,38 +59,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
),
),
const SizedBox(height: 16),
TextButton(
onPressed: () async {
final result = await showDialog<List<SubspaceTemplateModel>>(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return CreateSubSpaceModelDialog(
isEdit: true,
dialogTitle: 'Create Sub-space',
existingSubSpaces: subspaces,
);
},
);
if (result != null) {
// Update the subspaces
subspaces = result;
if (result.isNotEmpty) {
context
.read<CreateSpaceModelBloc>()
.add(AddSubspacesToSpaceTemplate(subspaces));
}
}
},
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
),
child: const ButtonContentWidget(
icon: Icons.add,
label: 'Create Sub Space',
),
),
_buildSubspacesSection(context, subspaces),
const SizedBox(height: 10),
TextButton(
onPressed: () async {
@ -145,4 +115,97 @@ class CreateSpaceModelDialog extends StatelessWidget {
),
);
}
Widget _buildSubspacesSection(
BuildContext context, List<SubspaceTemplateModel> subspaces) {
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',
),
)
: Row(
children: [
Expanded(
child: TextField(
readOnly: true,
decoration: InputDecoration(
filled: true,
fillColor: ColorsManager.whiteColors,
hintText: subspaces.map((e) => e.subspaceName).join(", "),
hintStyle:
const TextStyle(color: ColorsManager.spaceColor),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none,
),
),
),
),
const SizedBox(width: 10),
TextButton(
onPressed: () 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));
}
},
style: TextButton.styleFrom(
backgroundColor: ColorsManager.whiteColors,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide(color: ColorsManager.spaceColor),
),
),
child: const Text(
'Edit',
style: TextStyle(color: ColorsManager.spaceColor),
),
),
],
),
);
}
}