diff --git a/lib/pages/spaces_management/space_model/view/space_model_page.dart b/lib/pages/spaces_management/space_model/view/space_model_page.dart index dd36350a..9eb72d89 100644 --- a/lib/pages/spaces_management/space_model/view/space_model_page.dart +++ b/lib/pages/spaces_management/space_model/view/space_model_page.dart @@ -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( + create: (_) => CreateSpaceModelBloc(), + child: CreateSpaceModelDialog(products: products), + ); }, ); }, diff --git a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart index c152fcc8..a5a27923 100644 --- a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart +++ b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart @@ -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>( - 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() - .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 subspaces) { + return Container( + child: subspaces.isEmpty + ? TextButton( + style: TextButton.styleFrom( + overlayColor: Colors.transparent, + ), + onPressed: () async { + final result = await showDialog>( + 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() + .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>( + 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() + .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), + ), + ), + ], + ), + ); + } }