updated api

This commit is contained in:
hannathkadher
2024-11-18 15:36:33 +04:00
parent e33a07ac56
commit 836c44fd95
8 changed files with 125 additions and 75 deletions

View File

@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/common/buttons/add_space_button.dart';
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_space_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/widgets/curved_line_painter.dart';
import 'package:syncrow_web/pages/spaces_management/widgets/space_card_widget.dart';
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
import 'package:syncrow_web/pages/spaces_management/model/space_data_model.dart';
import 'package:syncrow_web/pages/spaces_management/model/connection_model.dart';
import 'package:syncrow_web/pages/spaces_management/widgets/space_container_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
@ -21,7 +21,7 @@ class CommunityStructureArea extends StatefulWidget {
class _CommunityStructureAreaState extends State<CommunityStructureArea> {
double canvasWidth = 1000;
double canvasHeight = 1000;
List<SpaceData> spaces = [];
List<SpaceModel> spaces = [];
List<Connection> connections = [];
@override
@ -81,7 +81,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
buildSpaceContainer: (int index) {
return SpaceContainerWidget(
index: index,
icon: spaces[index].icon,
icon: spaces[index].icon ?? '',
name: spaces[index].name,
);
},
@ -122,25 +122,51 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Community Structure',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Community Structure',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
if (widget.selectedCommunity != null)
Text(
widget.selectedCommunity!.name,
style: const TextStyle(
fontSize: 16, color: ColorsManager.blackColor),
),
],
),
if (widget.selectedCommunity != null)
Text(
widget.selectedCommunity!.name,
style: const TextStyle(
fontSize: 16, color: ColorsManager.blackColor),
// Show "Save" button only if there are spaces
if (spaces.isNotEmpty && widget.selectedCommunity != null )
ElevatedButton.icon(
onPressed: () {
_saveSpaces();
},
icon: const Icon(Icons.save, size: 18),
label: const Text("Save"),
style: ElevatedButton.styleFrom(
backgroundColor: ColorsManager.whiteColors,
foregroundColor: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
padding:
const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
side: BorderSide(color: Colors.grey.shade300),
elevation: 0,
),
),
],
),
);
}
void _updateNodePosition(SpaceData node, Offset newPosition) {
void _updateNodePosition(SpaceModel node, Offset newPosition) {
setState(() {
node.position = newPosition;
@ -188,15 +214,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
50, // Slightly above the center vertically
);
SpaceData newSpace =
SpaceData(name: name, icon: icon, position: centerPosition);
SpaceModel newSpace =
SpaceModel(name: name, icon: icon, position: centerPosition, isPrivate: false, children: []);
spaces.add(newSpace);
_updateNodePosition(newSpace, newSpace.position);
// Add connection for down-button
if (parentIndex != null && direction != null) {
SpaceData parentSpace = spaces[parentIndex];
SpaceModel parentSpace = spaces[parentIndex];
connections.add(Connection(
startSpace: parentSpace,
endSpace: newSpace,
@ -215,4 +241,10 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
spaces[index].isHovered = isHovered;
});
}
void _saveSpaces() {
// Implement your save functionality here
print("Spaces saved: ${spaces.length}");
}
}