mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
expansion only on clicking icon
This commit is contained in:
@ -5,8 +5,10 @@ class CustomExpansionTile extends StatefulWidget {
|
|||||||
final String title;
|
final String title;
|
||||||
final List<Widget>? children;
|
final List<Widget>? children;
|
||||||
final bool initiallyExpanded;
|
final bool initiallyExpanded;
|
||||||
|
final bool isSelected; // Add this to track selection
|
||||||
final bool? isExpanded; // External control over expansion
|
final bool? isExpanded; // External control over expansion
|
||||||
final ValueChanged<bool>? onExpansionChanged; // Notify when expansion changes
|
final ValueChanged<bool>? onExpansionChanged; // Notify when expansion changes
|
||||||
|
final VoidCallback? onItemSelected; // Callback for selecting the item
|
||||||
|
|
||||||
CustomExpansionTile({
|
CustomExpansionTile({
|
||||||
required this.title,
|
required this.title,
|
||||||
@ -14,6 +16,8 @@ class CustomExpansionTile extends StatefulWidget {
|
|||||||
this.initiallyExpanded = false,
|
this.initiallyExpanded = false,
|
||||||
this.isExpanded, // Allow external control over expansion
|
this.isExpanded, // Allow external control over expansion
|
||||||
this.onExpansionChanged, // Notify when expansion changes
|
this.onExpansionChanged, // Notify when expansion changes
|
||||||
|
this.onItemSelected, // Trigger item selection when name is tapped
|
||||||
|
required this.isSelected, // Add this to initialize selection state
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -22,7 +26,6 @@ class CustomExpansionTile extends StatefulWidget {
|
|||||||
|
|
||||||
class CustomExpansionTileState extends State<CustomExpansionTile> {
|
class CustomExpansionTileState extends State<CustomExpansionTile> {
|
||||||
bool _isExpanded = false; // Local expansion state
|
bool _isExpanded = false; // Local expansion state
|
||||||
bool _isChecked = false; // Local checkbox state
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -51,57 +54,66 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
// The main clickable row for the expansion tile
|
Row(
|
||||||
InkWell(
|
children: [
|
||||||
onTap: () {
|
// Checkbox with independent state management
|
||||||
setState(() {
|
Checkbox(
|
||||||
_isExpanded = !_isExpanded;
|
value: false,
|
||||||
widget.onExpansionChanged?.call(_isExpanded);
|
onChanged: (bool? value) {
|
||||||
});
|
setState(() {});
|
||||||
},
|
},
|
||||||
child: Row(
|
side: WidgetStateBorderSide.resolveWith((states) {
|
||||||
children: [
|
return const BorderSide(color: ColorsManager.grayBorder);
|
||||||
// Checkbox with independent state management
|
}),
|
||||||
Checkbox(
|
fillColor: WidgetStateProperty.resolveWith((states) {
|
||||||
value: _isChecked,
|
if (states.contains(WidgetState.selected)) {
|
||||||
onChanged: (bool? value) {
|
return ColorsManager.grayBorder;
|
||||||
|
} else {
|
||||||
|
return ColorsManager.checkBoxFillColor;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
checkColor: ColorsManager.whiteColors,
|
||||||
|
),
|
||||||
|
// Expand/collapse icon, now wrapped in a GestureDetector for specific onTap
|
||||||
|
if (widget.children != null && widget.children!.isNotEmpty)
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isChecked = value ?? false;
|
_isExpanded = !_isExpanded;
|
||||||
|
widget.onExpansionChanged?.call(_isExpanded);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
side: MaterialStateBorderSide.resolveWith((states) {
|
child: Icon(
|
||||||
return const BorderSide(color: ColorsManager.grayBorder);
|
|
||||||
}),
|
|
||||||
fillColor: MaterialStateProperty.resolveWith((states) {
|
|
||||||
if (states.contains(MaterialState.selected)) {
|
|
||||||
return ColorsManager.grayBorder;
|
|
||||||
} else {
|
|
||||||
return ColorsManager.checkBoxFillColor;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
checkColor: ColorsManager.whiteColors,
|
|
||||||
),
|
|
||||||
// Show the expand/collapse icon
|
|
||||||
if (widget.children != null && widget.children!.isNotEmpty)
|
|
||||||
Icon(
|
|
||||||
_isExpanded
|
_isExpanded
|
||||||
? Icons.keyboard_arrow_down
|
? Icons.keyboard_arrow_down
|
||||||
: Icons.keyboard_arrow_right,
|
: Icons.keyboard_arrow_right,
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
size: 16.0, // Adjusted size for better alignment
|
size: 16.0, // Adjusted size for better alignment
|
||||||
),
|
),
|
||||||
// The title text with dynamic styling
|
),
|
||||||
Expanded(
|
// The title text, wrapped in GestureDetector to handle selection
|
||||||
|
Expanded(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
// Triggerxq the onItemSelected callback when the name is tapped
|
||||||
|
if (widget.onItemSelected != null) {
|
||||||
|
widget.onItemSelected!();
|
||||||
|
}
|
||||||
|
debugPrint('${widget.title} ${widget.isSelected} tapped for selection');
|
||||||
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
_capitalizeFirstLetter(widget.title),
|
_capitalizeFirstLetter(widget.title),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color:ColorsManager.lightGrayColor,
|
color: widget.isSelected
|
||||||
|
? Colors.black // Change color to black when selected
|
||||||
|
: ColorsManager
|
||||||
|
.lightGrayColor, // Gray when not selected
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
// The expanded section (children) that shows when the tile is expanded
|
// The expanded section (children) that shows when the tile is expanded
|
||||||
if (_isExpanded &&
|
if (_isExpanded &&
|
||||||
|
@ -1,45 +1,35 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_web/common/custom_expansion_tile.dart';
|
import 'package:syncrow_web/common/custom_expansion_tile.dart';
|
||||||
|
|
||||||
class CommunityTile extends StatefulWidget {
|
class CommunityTile extends StatelessWidget {
|
||||||
final String title;
|
final String title;
|
||||||
final List<Widget>? children;
|
final List<Widget>? children;
|
||||||
final bool initiallyExpanded;
|
final bool isExpanded;
|
||||||
|
final bool isSelected;
|
||||||
final Function(String, bool) onExpansionChanged;
|
final Function(String, bool) onExpansionChanged;
|
||||||
|
final Function() onItemSelected;
|
||||||
|
|
||||||
const CommunityTile({
|
const CommunityTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.title,
|
required this.title,
|
||||||
required this.initiallyExpanded,
|
required this.isExpanded,
|
||||||
required this.onExpansionChanged,
|
required this.onExpansionChanged,
|
||||||
|
required this.onItemSelected,
|
||||||
|
required this.isSelected,
|
||||||
this.children,
|
this.children,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
|
||||||
_CommunityTileState createState() => _CommunityTileState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CommunityTileState extends State<CommunityTile> {
|
|
||||||
late bool _isExpanded;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_isExpanded = widget.initiallyExpanded;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CustomExpansionTile(
|
return CustomExpansionTile(
|
||||||
title: widget.title,
|
title: title,
|
||||||
initiallyExpanded: _isExpanded,
|
initiallyExpanded: isExpanded,
|
||||||
|
isSelected: isSelected,
|
||||||
onExpansionChanged: (bool expanded) {
|
onExpansionChanged: (bool expanded) {
|
||||||
setState(() {
|
onExpansionChanged(title, expanded);
|
||||||
_isExpanded = expanded;
|
|
||||||
});
|
|
||||||
widget.onExpansionChanged(widget.title, expanded);
|
|
||||||
},
|
},
|
||||||
children: widget.children ?? [],
|
onItemSelected: onItemSelected,
|
||||||
|
children: children ?? [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,20 +175,34 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
|
|
||||||
Widget _buildCommunityTile(CommunityModel community) {
|
Widget _buildCommunityTile(CommunityModel community) {
|
||||||
bool hasChildren = community.spaces.isNotEmpty;
|
bool hasChildren = community.spaces.isNotEmpty;
|
||||||
bool isSelectedCommunity = _selectedCommunityUuid == community.uuid;
|
bool isSelectedCommunity = _selectedCommunityUuid ==
|
||||||
|
community.uuid; // Check if this community is selected
|
||||||
|
|
||||||
debugPrint(
|
debugPrint('Building CommunityTile for ${community.name} with UUID: ${community.uuid}');
|
||||||
'Building CommunityTile for ${community.name}, hasChildren: $hasChildren');
|
debugPrint('Currently selected community UUID: $_selectedCommunityUuid');
|
||||||
|
debugPrint('Is selected: $isSelectedCommunity');
|
||||||
|
|
||||||
return CommunityTile(
|
return CommunityTile(
|
||||||
title: community.name,
|
title: community.name,
|
||||||
initiallyExpanded: isSelectedCommunity,
|
isSelected: isSelectedCommunity,
|
||||||
|
isExpanded: false,
|
||||||
|
onItemSelected: () {
|
||||||
|
setState(() {
|
||||||
|
_selectedSpaceUuid = community.uuid; // Update the selected community
|
||||||
|
debugPrint(
|
||||||
|
'Selected community: ${community.name}, UUID: ${community.uuid}');
|
||||||
|
debugPrint(
|
||||||
|
'Updated selected community UUID: $_selectedCommunityUuid');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (widget.onCommunitySelected != null) {
|
||||||
|
widget.onCommunitySelected!(community); // Pass the entire community
|
||||||
|
}
|
||||||
|
},
|
||||||
onExpansionChanged: (String title, bool expanded) {
|
onExpansionChanged: (String title, bool expanded) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'CommunityTile onExpansionChanged called for $title, expanded: $expanded');
|
'CommunityTile onExpansionChanged called for $title, expanded: $expanded');
|
||||||
_handleExpansionChange(community.uuid, expanded);
|
_handleExpansionChange(community.uuid, expanded);
|
||||||
if (widget.onCommunitySelected != null) {
|
|
||||||
widget.onCommunitySelected!(community); // Pass the entire community
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
children: hasChildren
|
children: hasChildren
|
||||||
? community.spaces.map((space) => _buildSpaceTile(space)).toList()
|
? community.spaces.map((space) => _buildSpaceTile(space)).toList()
|
||||||
|
@ -31,6 +31,7 @@ class _SpaceTileState extends State<SpaceTile> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CustomExpansionTile(
|
return CustomExpansionTile(
|
||||||
|
isSelected: false,
|
||||||
title: widget.title,
|
title: widget.title,
|
||||||
initiallyExpanded: _isExpanded,
|
initiallyExpanded: _isExpanded,
|
||||||
onExpansionChanged: (bool expanded) {
|
onExpansionChanged: (bool expanded) {
|
||||||
|
Reference in New Issue
Block a user