fixed re-rendering of community widget

This commit is contained in:
hannathkadher
2024-10-08 20:37:04 +04:00
parent 1156af9b8e
commit 33712b7690
4 changed files with 90 additions and 30 deletions

View File

@ -1,29 +1,45 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/common/custom_expansion_tile.dart';
class CommunityTile extends StatelessWidget {
class CommunityTile extends StatefulWidget {
final String title;
final bool isExpanded;
final Function(String, bool) onExpansionChanged;
final List<Widget>? children;
final bool initiallyExpanded;
final Function(String, bool) onExpansionChanged;
const CommunityTile({
Key? key,
required this.title,
required this.isExpanded,
required this.initiallyExpanded,
required this.onExpansionChanged,
this.children,
}) : super(key: key);
@override
_CommunityTileState createState() => _CommunityTileState();
}
class _CommunityTileState extends State<CommunityTile> {
late bool _isExpanded;
@override
void initState() {
super.initState();
_isExpanded = widget.initiallyExpanded;
}
@override
Widget build(BuildContext context) {
return CustomExpansionTile(
title: title,
initiallyExpanded: isExpanded,
title: widget.title,
initiallyExpanded: _isExpanded,
onExpansionChanged: (bool expanded) {
onExpansionChanged(title, expanded);
setState(() {
_isExpanded = expanded;
});
widget.onExpansionChanged(widget.title, expanded);
},
children: children ?? [],
children: widget.children ?? [],
);
}
}

View File

@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:syncrow_web/common/custom_expansion_tile.dart';
import 'package:syncrow_web/common/search_bar.dart';
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
import 'package:syncrow_web/pages/spaces_management/widgets/community_tile.dart';
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_community_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/widgets/space_tile_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/style.dart';
@ -144,7 +144,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
'Building CommunityTile for ${community.name}, hasChildren: $hasChildren');
return CommunityTile(
title: community.name,
isExpanded: _expandedTiles[community.uuid] ?? false,
initiallyExpanded: false,
onExpansionChanged: (String title, bool expanded) {
debugPrint(
'CommunityTile onExpansionChanged called for $title, expanded: $expanded');
@ -159,9 +159,9 @@ class _SidebarWidgetState extends State<SidebarWidget> {
Widget _buildSpaceTile(SpaceModel space) {
debugPrint(
'Building SpaceTile for ${space.name}, hasChildren: ${space.children.isNotEmpty}');
return CustomExpansionTile(
return SpaceTile(
title: space.name,
isExpanded: _expandedTiles[space.uuid] ?? false,
initiallyExpanded: false,
onExpansionChanged: (bool expanded) {
debugPrint(
'SpaceTile onExpansionChanged called for ${space.name}, expanded: $expanded');
@ -175,11 +175,5 @@ class _SidebarWidgetState extends State<SidebarWidget> {
);
}
void _handleExpansionChange(String uuid, bool expanded) {
setState(() {
_expandedTiles[uuid] = expanded;
debugPrint('_expandedTiles updated: $_expandedTiles');
});
widget.onCommunitySelected?.call(uuid);
}
void _handleExpansionChange(String uuid, bool expanded) {}
}

View File

@ -0,0 +1,45 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/common/custom_expansion_tile.dart';
class SpaceTile extends StatefulWidget {
final String title;
final bool initiallyExpanded;
final ValueChanged<bool> onExpansionChanged;
final List<Widget>? children;
const SpaceTile({
Key? key,
required this.title,
required this.initiallyExpanded,
required this.onExpansionChanged,
this.children,
}) : super(key: key);
@override
_SpaceTileState createState() => _SpaceTileState();
}
class _SpaceTileState extends State<SpaceTile> {
late bool _isExpanded;
@override
void initState() {
super.initState();
_isExpanded = widget.initiallyExpanded;
}
@override
Widget build(BuildContext context) {
return CustomExpansionTile(
title: widget.title,
initiallyExpanded: _isExpanded,
onExpansionChanged: (bool expanded) {
setState(() {
_isExpanded = expanded;
});
widget.onExpansionChanged(expanded);
},
children: widget.children ?? [],
);
}
}