mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
270 lines
14 KiB
Dart
270 lines
14 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:syncrow_web/common/widgets/search_bar.dart';
|
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart';
|
|
import 'package:syncrow_web/pages/space_tree/view/custom_expansion.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
|
import 'package:syncrow_web/utils/color_manager.dart';
|
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
|
import 'package:syncrow_web/utils/style.dart';
|
|
|
|
class SpaceTreeView extends StatefulWidget {
|
|
final bool? isSide;
|
|
final Function onSelect;
|
|
const SpaceTreeView({required this.onSelect, this.isSide, super.key});
|
|
|
|
@override
|
|
State<SpaceTreeView> createState() => _SpaceTreeViewState();
|
|
}
|
|
|
|
class _SpaceTreeViewState extends State<SpaceTreeView> {
|
|
final ScrollController _scrollController = ScrollController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_scrollController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<SpaceTreeBloc, SpaceTreeState>(builder: (context, state) {
|
|
List<CommunityModel> list = state.isSearching ? state.filteredCommunity : state.communityList;
|
|
return Container(
|
|
height: MediaQuery.sizeOf(context).height,
|
|
decoration: widget.isSide == true
|
|
? subSectionContainerDecoration.copyWith(color: ColorsManager.whiteColors)
|
|
: const BoxDecoration(color: ColorsManager.whiteColors),
|
|
child: state is SpaceTreeLoadingState
|
|
? const Center(child: CircularProgressIndicator())
|
|
: Column(
|
|
children: [
|
|
widget.isSide == true
|
|
? Container(
|
|
decoration: const BoxDecoration(
|
|
color: ColorsManager.circleRolesBackground,
|
|
borderRadius: BorderRadius.only(
|
|
topRight: Radius.circular(20), topLeft: Radius.circular(20)),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
|
border: Border.all(color: ColorsManager.grayBorder)),
|
|
child: TextFormField(
|
|
style: const TextStyle(color: Colors.black),
|
|
onChanged: (value) {
|
|
context.read<SpaceTreeBloc>().add(SearchQueryEvent(value));
|
|
},
|
|
decoration: textBoxDecoration(radios: 20)!.copyWith(
|
|
fillColor: Colors.white,
|
|
suffixIcon: Padding(
|
|
padding: const EdgeInsets.only(right: 16),
|
|
child: SvgPicture.asset(
|
|
Assets.textFieldSearch,
|
|
width: 24,
|
|
height: 24,
|
|
),
|
|
),
|
|
hintStyle: context.textTheme.bodyMedium?.copyWith(
|
|
fontWeight: FontWeight.w400,
|
|
fontSize: 12,
|
|
color: ColorsManager.textGray),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: CustomSearchBar(
|
|
onSearchChanged: (query) {
|
|
context.read<SpaceTreeBloc>().add(SearchQueryEvent(query));
|
|
},
|
|
),
|
|
const SizedBox(height: 16),
|
|
Expanded(
|
|
child: ListView(
|
|
shrinkWrap: true,
|
|
scrollDirection: Axis.horizontal,
|
|
children: [
|
|
Container(
|
|
width: MediaQuery.sizeOf(context).width * 0.5,
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: list.isEmpty
|
|
? Center(
|
|
child: Text(
|
|
'No results found',
|
|
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
|
color: ColorsManager.lightGrayColor,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
)
|
|
: Scrollbar(
|
|
scrollbarOrientation: ScrollbarOrientation.left,
|
|
thumbVisibility: true,
|
|
controller: _scrollController,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 16),
|
|
child: ListView(
|
|
controller: _scrollController,
|
|
shrinkWrap: true,
|
|
children: list
|
|
.map(
|
|
(community) => CustomExpansionTileSpaceTree(
|
|
title: community.name,
|
|
isSelected: state.selectedCommunities
|
|
.contains(community.uuid),
|
|
isSoldCheck: state.selectedCommunities
|
|
.contains(community.uuid),
|
|
onExpansionChanged: () {
|
|
context
|
|
.read<SpaceTreeBloc>()
|
|
.add(OnCommunityExpanded(community.uuid));
|
|
},
|
|
isExpanded: state.expandedCommunities
|
|
.contains(community.uuid),
|
|
onItemSelected: () {
|
|
context.read<SpaceTreeBloc>().add(
|
|
OnCommunitySelected(
|
|
community.uuid, community.spaces));
|
|
widget.onSelect();
|
|
},
|
|
children: community.spaces.map((space) {
|
|
return CustomExpansionTileSpaceTree(
|
|
title: space.name,
|
|
isExpanded:
|
|
state.expandedSpaces.contains(space.uuid),
|
|
onItemSelected: () {
|
|
context.read<SpaceTreeBloc>().add(
|
|
OnSpaceSelected(community, space.uuid ?? '',
|
|
space.children));
|
|
widget.onSelect();
|
|
},
|
|
onExpansionChanged: () {
|
|
context.read<SpaceTreeBloc>().add(
|
|
OnSpaceExpanded(
|
|
community.uuid, space.uuid ?? ''));
|
|
},
|
|
isSelected:
|
|
state.selectedSpaces.contains(space.uuid) ||
|
|
state.soldCheck.contains(space.uuid),
|
|
isSoldCheck: state.soldCheck.contains(space.uuid),
|
|
children: _buildNestedSpaces(
|
|
context, state, space, community),
|
|
);
|
|
}).toList(),
|
|
),
|
|
)
|
|
.toList(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// Expanded(
|
|
// child: Padding(
|
|
// padding: const EdgeInsets.all(8.0),
|
|
// child: list.isEmpty
|
|
// ? Center(
|
|
// child: Text(
|
|
// 'No results found',
|
|
// style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
|
// color: ColorsManager.lightGrayColor, // Gray when not selected
|
|
// fontWeight: FontWeight.w400,
|
|
// ),
|
|
// ),
|
|
// )
|
|
// : ListView(
|
|
// shrinkWrap: true,
|
|
// children: list
|
|
// .map(
|
|
// (community) => CustomExpansionTileSpaceTree(
|
|
// title: community.name,
|
|
// isSelected:
|
|
// state.selectedCommunities.contains(community.uuid),
|
|
// isSoldCheck:
|
|
// state.selectedCommunities.contains(community.uuid),
|
|
// onExpansionChanged: () {
|
|
// context
|
|
// .read<SpaceTreeBloc>()
|
|
// .add(OnCommunityExpanded(community.uuid));
|
|
// },
|
|
// isExpanded:
|
|
// state.expandedCommunities.contains(community.uuid),
|
|
// onItemSelected: () {
|
|
// context.read<SpaceTreeBloc>().add(
|
|
// OnCommunitySelected(community.uuid, community.spaces));
|
|
|
|
// onSelect();
|
|
// },
|
|
// children: community.spaces.map((space) {
|
|
// return CustomExpansionTileSpaceTree(
|
|
// title: space.name,
|
|
// isExpanded: state.expandedSpaces.contains(space.uuid),
|
|
// onItemSelected: () {
|
|
// context.read<SpaceTreeBloc>().add(OnSpaceSelected(
|
|
// community.uuid, space.uuid ?? '', space.children));
|
|
// onSelect();
|
|
// },
|
|
// onExpansionChanged: () {
|
|
// context.read<SpaceTreeBloc>().add(
|
|
// OnSpaceExpanded(community.uuid, space.uuid ?? ''));
|
|
// },
|
|
// isSelected: state.selectedSpaces.contains(space.uuid) ||
|
|
// state.soldCheck.contains(space.uuid),
|
|
// isSoldCheck: state.soldCheck.contains(space.uuid),
|
|
// children: _buildNestedSpaces(
|
|
// context, state, space, community.uuid),
|
|
// );
|
|
// }).toList(),
|
|
// ),
|
|
// )
|
|
// .toList(),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
],
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
List<Widget> _buildNestedSpaces(
|
|
BuildContext context, SpaceTreeState state, SpaceModel space, CommunityModel community) {
|
|
return space.children.map((child) {
|
|
return CustomExpansionTileSpaceTree(
|
|
isSelected:
|
|
state.selectedSpaces.contains(child.uuid) || state.soldCheck.contains(child.uuid),
|
|
isSoldCheck: state.soldCheck.contains(child.uuid),
|
|
title: child.name,
|
|
isExpanded: state.expandedSpaces.contains(child.uuid),
|
|
onItemSelected: () {
|
|
context
|
|
.read<SpaceTreeBloc>()
|
|
.add(OnSpaceSelected(community, child.uuid ?? '', child.children));
|
|
widget.onSelect();
|
|
},
|
|
onExpansionChanged: () {
|
|
context.read<SpaceTreeBloc>().add(OnSpaceExpanded(community.uuid, child.uuid ?? ''));
|
|
},
|
|
children: _buildNestedSpaces(context, state, child, community),
|
|
);
|
|
}).toList();
|
|
}
|
|
}
|