updated LoadedSpaceView

This commit is contained in:
hannathkadher
2024-11-28 19:54:04 +04:00
parent b75f8a3440
commit 0b2d44fc2b

View File

@ -36,32 +36,22 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return BlocProvider(
create: (context) => create: (context) => SpaceManagementBloc(_api, _productApi)
SpaceManagementBloc(_api, _productApi)..add(LoadCommunityAndSpacesEvent()), ..add(LoadCommunityAndSpacesEvent()),
child: WebScaffold( child: WebScaffold(
appBarTitle: Text('Space Management', style: Theme.of(context).textTheme.headlineLarge), appBarTitle: Text('Space Management',
style: Theme.of(context).textTheme.headlineLarge),
enableMenuSidebar: false, enableMenuSidebar: false,
rightBody: const NavigateHomeGridView(), rightBody: const NavigateHomeGridView(),
scaffoldBody: scaffoldBody: BlocBuilder<SpaceManagementBloc, SpaceManagementState>(
BlocBuilder<SpaceManagementBloc, SpaceManagementState>(builder: (context, state) { builder: (context, state) {
if (state is SpaceManagementLoading) { if (state is SpaceManagementLoading) {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
} else if (state is SpaceManagementLoaded) { } else if (state is SpaceManagementLoaded) {
int selectedIndex = state.communities.indexWhere(
(community) => community.uuid == selectedCommunity?.uuid,
);
if (selectedIndex != -1) {
selectedCommunity = state.communities[selectedIndex];
} else if (state.selectedCommunity != null) {
selectedCommunity = state.selectedCommunity;
} else {
selectedCommunity = null;
selectedSpace = null;
}
return LoadedSpaceView( return LoadedSpaceView(
communities: state.communities, communities: state.communities,
selectedCommunity: selectedCommunity, selectedCommunity: state.selectedCommunity,
selectedSpace: selectedSpace, selectedSpace: state.selectedSpace,
products: state.products, products: state.products,
onCommunitySelected: (community) { onCommunitySelected: (community) {
setState(() { setState(() {