mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
fixed re-rendering of community widget
This commit is contained in:
@ -5,8 +5,8 @@ class CustomExpansionTile extends StatefulWidget {
|
||||
final String title;
|
||||
final List<Widget>? children;
|
||||
final bool initiallyExpanded;
|
||||
final bool? isExpanded; // New parameter to control expansion
|
||||
final ValueChanged<bool>? onExpansionChanged; // Callback for expansion change
|
||||
final bool? isExpanded; // External control over expansion
|
||||
final ValueChanged<bool>? onExpansionChanged; // Notify when expansion changes
|
||||
|
||||
CustomExpansionTile({
|
||||
required this.title,
|
||||
@ -21,8 +21,8 @@ class CustomExpansionTile extends StatefulWidget {
|
||||
}
|
||||
|
||||
class CustomExpansionTileState extends State<CustomExpansionTile> {
|
||||
bool _isExpanded = false;
|
||||
bool _isChecked = false;
|
||||
bool _isExpanded = false; // Local expansion state
|
||||
bool _isChecked = false; // Local checkbox state
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -33,6 +33,7 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
||||
@override
|
||||
void didUpdateWidget(CustomExpansionTile oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// Sync local state with external control of expansion state
|
||||
if (widget.isExpanded != null && widget.isExpanded != _isExpanded) {
|
||||
setState(() {
|
||||
_isExpanded = widget.isExpanded!;
|
||||
@ -40,6 +41,7 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
||||
}
|
||||
}
|
||||
|
||||
// Utility function to capitalize the first letter of the title
|
||||
String _capitalizeFirstLetter(String text) {
|
||||
if (text.isEmpty) return text;
|
||||
return text[0].toUpperCase() + text.substring(1);
|
||||
@ -49,6 +51,7 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
// The main clickable row for the expansion tile
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
@ -58,7 +61,7 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
// Customizing the Checkbox
|
||||
// Checkbox with independent state management
|
||||
Checkbox(
|
||||
value: _isChecked,
|
||||
onChanged: (bool? value) {
|
||||
@ -66,11 +69,11 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
||||
_isChecked = value ?? false;
|
||||
});
|
||||
},
|
||||
side: WidgetStateBorderSide.resolveWith((states) {
|
||||
side: MaterialStateBorderSide.resolveWith((states) {
|
||||
return const BorderSide(color: ColorsManager.grayBorder);
|
||||
}),
|
||||
fillColor: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
fillColor: MaterialStateProperty.resolveWith((states) {
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return ColorsManager.grayBorder;
|
||||
} else {
|
||||
return ColorsManager.checkBoxFillColor;
|
||||
@ -78,15 +81,16 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
||||
}),
|
||||
checkColor: ColorsManager.whiteColors,
|
||||
),
|
||||
// Show the expand/collapse icon
|
||||
if (widget.children != null && widget.children!.isNotEmpty)
|
||||
Icon(
|
||||
_isExpanded
|
||||
? Icons.keyboard_arrow_down
|
||||
: Icons.keyboard_arrow_right,
|
||||
color: Colors.grey,
|
||||
size: 16.0, // Reduced icon size
|
||||
size: 16.0, // Adjusted size for better alignment
|
||||
),
|
||||
// Title Text
|
||||
// The title text with dynamic styling
|
||||
Expanded(
|
||||
child: Text(
|
||||
_capitalizeFirstLetter(widget.title),
|
||||
@ -101,11 +105,12 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
||||
],
|
||||
),
|
||||
),
|
||||
// The expanded section (children) that shows when the tile is expanded
|
||||
if (_isExpanded &&
|
||||
widget.children != null &&
|
||||
widget.children!.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 48.0), // Indent the children
|
||||
padding: const EdgeInsets.only(left: 48.0), // Indented children
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: widget.children!,
|
||||
|
Reference in New Issue
Block a user