diff --git a/lib/pages/spaces_management/widgets/blank_community_widget.dart b/lib/pages/spaces_management/widgets/blank_community_widget.dart index 6b97c956..a57f3c18 100644 --- a/lib/pages/spaces_management/widgets/blank_community_widget.dart +++ b/lib/pages/spaces_management/widgets/blank_community_widget.dart @@ -72,6 +72,7 @@ class _BlankCommunityWidgetState extends State { showDialog( context: parentContext, builder: (context) => CreateCommunityDialog( + isEditMode: false, communities: widget.communities, onCreateCommunity: (String communityName, String description) { parentContext.read().add( @@ -84,4 +85,5 @@ class _BlankCommunityWidgetState extends State { ), ); } + } diff --git a/lib/pages/spaces_management/widgets/community_structure_header_widget.dart b/lib/pages/spaces_management/widgets/community_structure_header_widget.dart index a940ecf6..72d6228e 100644 --- a/lib/pages/spaces_management/widgets/community_structure_header_widget.dart +++ b/lib/pages/spaces_management/widgets/community_structure_header_widget.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_web/pages/common/buttons/default_button.dart'; +import 'package:syncrow_web/pages/spaces_management/model/community_model.dart'; +import 'package:syncrow_web/pages/spaces_management/widgets/dialogs/create_community_dialog.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; -class CommunityStructureHeader extends StatelessWidget { +class CommunityStructureHeader extends StatefulWidget { final String? communityName; final bool isEditingName; final bool isSave; @@ -13,19 +15,28 @@ class CommunityStructureHeader extends StatelessWidget { final VoidCallback onDelete; final VoidCallback onEditName; final ValueChanged onNameSubmitted; + final List communities; + final CommunityModel? community; - const CommunityStructureHeader({ - Key? key, - required this.communityName, - required this.isSave, - required this.isEditingName, - required this.nameController, - required this.onSave, - required this.onDelete, - required this.onEditName, - required this.onNameSubmitted, - }) : super(key: key); + const CommunityStructureHeader( + {super.key, + required this.communityName, + required this.isSave, + required this.isEditingName, + required this.nameController, + required this.onSave, + required this.onDelete, + required this.onEditName, + required this.onNameSubmitted, + this.community, + required this.communities}); + @override + State createState() => + _CommunityStructureHeaderState(); +} + +class _CommunityStructureHeaderState extends State { @override Widget build(BuildContext context) { final theme = Theme.of(context); @@ -60,47 +71,62 @@ class CommunityStructureHeader extends StatelessWidget { ); } + void _showCreateCommunityDialog(BuildContext parentContext) { + showDialog( + context: parentContext, + builder: (context) => CreateCommunityDialog( + isEditMode: true, + communities: widget.communities, + communityToEdit: widget.community, + onCreateCommunity: (String communityName, String description) { + widget.onNameSubmitted(communityName); + }, + ), + ); + } + Widget _buildCommunityInfo(ThemeData theme, double screenWidth) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Community Structure', - style: theme.textTheme.headlineLarge?.copyWith(color: ColorsManager.blackColor), + style: theme.textTheme.headlineLarge + ?.copyWith(color: ColorsManager.blackColor), ), - if (communityName != null) + if (widget.communityName != null) Row( children: [ Expanded( child: Row( children: [ - if (!isEditingName) + if (!widget.isEditingName) Flexible( child: Text( - communityName!, - style: - theme.textTheme.bodyLarge?.copyWith(color: ColorsManager.blackColor), + widget.communityName!, + style: theme.textTheme.bodyLarge + ?.copyWith(color: ColorsManager.blackColor), overflow: TextOverflow.ellipsis, maxLines: 1, ), ), - if (isEditingName) + if (widget.isEditingName) SizedBox( width: screenWidth * 0.1, child: TextField( - controller: nameController, + controller: widget.nameController, decoration: const InputDecoration( border: InputBorder.none, isDense: true, ), - style: - theme.textTheme.bodyLarge?.copyWith(color: ColorsManager.blackColor), - onSubmitted: onNameSubmitted, + style: theme.textTheme.bodyLarge + ?.copyWith(color: ColorsManager.blackColor), + onSubmitted: widget.onNameSubmitted, ), ), const SizedBox(width: 2), GestureDetector( - onTap: onEditName, + onTap: () => _showCreateCommunityDialog(context), child: SvgPicture.asset( Assets.iconEdit, width: 16, @@ -110,7 +136,7 @@ class CommunityStructureHeader extends StatelessWidget { ], ), ), - if (isSave) ...[ + if (widget.isSave) ...[ const SizedBox(width: 8), _buildActionButtons(theme), ], @@ -127,8 +153,9 @@ class CommunityStructureHeader extends StatelessWidget { children: [ _buildButton( label: "Save", - icon: const Icon(Icons.save, size: 18, color: ColorsManager.spaceColor), - onPressed: onSave, + icon: const Icon(Icons.save, + size: 18, color: ColorsManager.spaceColor), + onPressed: widget.onSave, theme: theme), ], ); @@ -159,7 +186,8 @@ class CommunityStructureHeader extends StatelessWidget { Flexible( child: Text( label, - style: theme.textTheme.bodySmall?.copyWith(color: ColorsManager.blackColor), + style: theme.textTheme.bodySmall + ?.copyWith(color: ColorsManager.blackColor), overflow: TextOverflow.ellipsis, maxLines: 1, ), diff --git a/lib/pages/spaces_management/widgets/community_structure_widget.dart b/lib/pages/spaces_management/widgets/community_structure_widget.dart index 22f0d218..3789b3c9 100644 --- a/lib/pages/spaces_management/widgets/community_structure_widget.dart +++ b/lib/pages/spaces_management/widgets/community_structure_widget.dart @@ -119,7 +119,9 @@ class _CommunityStructureAreaState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ CommunityStructureHeader( + communities: widget.communities, communityName: widget.selectedCommunity?.name, + community: widget.selectedCommunity, isSave: isSave(spaces), isEditingName: isEditingName, nameController: _nameController, diff --git a/lib/pages/spaces_management/widgets/dialogs/create_community_dialog.dart b/lib/pages/spaces_management/widgets/dialogs/create_community_dialog.dart index 19ca8a99..e2208713 100644 --- a/lib/pages/spaces_management/widgets/dialogs/create_community_dialog.dart +++ b/lib/pages/spaces_management/widgets/dialogs/create_community_dialog.dart @@ -7,9 +7,16 @@ import 'package:syncrow_web/utils/color_manager.dart'; class CreateCommunityDialog extends StatefulWidget { final Function(String name, String description) onCreateCommunity; final List communities; + final bool isEditMode; + final CommunityModel? communityToEdit; - const CreateCommunityDialog( - {super.key, required this.onCreateCommunity, required this.communities}); + const CreateCommunityDialog({ + super.key, + required this.onCreateCommunity, + required this.communities, + required this.isEditMode, + this.communityToEdit, + }); @override CreateCommunityDialogState createState() => CreateCommunityDialogState(); @@ -19,6 +26,16 @@ class CreateCommunityDialogState extends State { String enteredName = ''; bool isNameFieldExist = false; bool isNameEmpty = false; + late TextEditingController nameController; + + @override + void initState() { + super.initState(); + // Initialize fields for edit mode or set defaults for create mode + nameController = TextEditingController( + text: widget.isEditMode ? widget.communityToEdit?.name ?? '' : '', + ); + } @override Widget build(BuildContext context) { @@ -52,9 +69,9 @@ class CreateCommunityDialogState extends State { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text( - 'Community Name', - style: TextStyle( + Text( + widget.isEditMode ? 'Edit Community Name' : 'Community Name', + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), @@ -62,11 +79,14 @@ class CreateCommunityDialogState extends State { const SizedBox(height: 16), // Input field for the community name TextField( + controller: nameController, onChanged: (value) { setState(() { enteredName = value.trim(); isNameFieldExist = widget.communities.any( - (community) => community.name == enteredName, + (community) => + community.name == enteredName && + widget.communityToEdit != community, ); if (value.isEmpty) { isNameEmpty = true; @@ -99,7 +119,8 @@ class CreateCommunityDialogState extends State { borderSide: BorderSide( color: isNameFieldExist || isNameEmpty ? ColorsManager.red - : ColorsManager.boxColor, width: 1), + : ColorsManager.boxColor, + width: 1), borderRadius: BorderRadius.circular(10), ), focusedBorder: OutlineInputBorder(