updated blank structure

This commit is contained in:
hannathkadher
2024-11-24 02:28:28 +04:00
parent 7806d3de7d
commit 5ac7eb0301
5 changed files with 30 additions and 8 deletions

View File

@ -27,10 +27,25 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
UpdateCommunityEvent event,
Emitter<SpaceManagementState> emit,
) async {
final previousState = state;
try {
emit(SpaceManagementLoading());
final success = await _api.updateCommunity(event.communityUuid, event.name);
if (success) {
if (previousState is SpaceManagementLoaded) {
final updatedCommunities = List<CommunityModel>.from(previousState.communities);
for(var community in updatedCommunities){
if(community.uuid == event.communityUuid){
community.name = event.name;
break;
}
}
emit(SpaceManagementLoaded(
communities: updatedCommunities,
products: previousState.products,
selectedCommunity: previousState.selectedCommunity,
));
}
add(LoadCommunityAndSpacesEvent());
} else {
emit(const SpaceManagementError('Failed to update the community.'));
@ -125,17 +140,16 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
emit(SpaceManagementLoading());
try {
CommunityModel? newCommunity = await _api.createCommunity(
event.name,
event.description
);
CommunityModel? newCommunity = await _api.createCommunity(event.name, event.description);
if (newCommunity != null) {
if (previousState is SpaceManagementLoaded) {
final updatedCommunities = List<CommunityModel>.from(previousState.communities)
..add(newCommunity);
emit(SpaceManagementLoaded(
communities: updatedCommunities, products: _cachedProducts ?? []));
communities: updatedCommunities,
products: _cachedProducts ?? [],
selectedCommunity: newCommunity));
}
} else {
emit(const SpaceManagementError('Error creating community'));

View File

@ -16,9 +16,11 @@ class SpaceManagementLoading extends SpaceManagementState {}
class SpaceManagementLoaded extends SpaceManagementState {
final List<CommunityModel> communities;
final List<ProductModel> products; // Include products in the state
final List<ProductModel> products;
CommunityModel? selectedCommunity; // Include products in the state
SpaceManagementLoaded({required this.communities, required this.products});
SpaceManagementLoaded(
{required this.communities, required this.products, this.selectedCommunity});
}
class SpaceCreationSuccess extends SpaceManagementState {

View File

@ -56,6 +56,8 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
);
if (selectedIndex != -1) {
selectedCommunity = state.communities[selectedIndex];
} else if (state.selectedCommunity != null) {
selectedCommunity = state.selectedCommunity;
} else {
selectedCommunity = null;
selectedSpace = null;

View File

@ -109,7 +109,9 @@ class CommunityStructureHeader extends StatelessWidget {
onPressed: onSave,
),
if (isSave) const SizedBox(width: 10),
if (communityName != null && communityName != '')
/*
Commenting till finalize delete
if (communityName != null && communityName != '')
_buildButton(
label: "Delete",
icon: SvgPicture.asset(
@ -119,6 +121,7 @@ class CommunityStructureHeader extends StatelessWidget {
),
onPressed: onDelete,
),
*/
],
);
}

View File

@ -52,6 +52,7 @@ abstract class ColorsManager {
static const Color counterBackgroundColor = Color(0xCCF4F4F4);
static const Color neutralGray = Color(0xFFE5E5E5);
static const Color warningRed = Color(0xFFFF6465);
static const Color borderColor = Color(0xFFE5E5E5);
}
//background: #background: #5D5D5D;