Files
syncrow-web/lib/common/widgets/custom_expansion_tile.dart
Faris Armoush 7d77809750 Refactor CustomExpansionTile and SpaceDetailsDialogHelper for improved functionality and UI consistency
- Updated CustomExpansionTile to enhance selection state handling and UI responsiveness.
- Integrated success and error snackbars in SpaceDetailsDialogHelper for better user feedback during space creation and updates.
- Removed redundant comments and improved code readability.
2025-07-24 14:51:07 +03:00

107 lines
3.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class CustomExpansionTile extends StatefulWidget {
final String title;
final List<Widget>? children;
final bool initiallyExpanded;
final bool isSelected;
final bool? isExpanded;
final ValueChanged<bool>? onExpansionChanged;
final VoidCallback? onItemSelected;
const CustomExpansionTile({
super.key,
required this.title,
this.children,
this.initiallyExpanded = false,
this.isExpanded,
this.onExpansionChanged,
this.onItemSelected,
required this.isSelected,
});
@override
CustomExpansionTileState createState() => CustomExpansionTileState();
}
class CustomExpansionTileState extends State<CustomExpansionTile> {
bool _isExpanded = false;
@override
void initState() {
super.initState();
_isExpanded = widget.initiallyExpanded;
}
@override
void didUpdateWidget(CustomExpansionTile oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isExpanded != null && widget.isExpanded != _isExpanded) {
setState(() {
_isExpanded = widget.isExpanded!;
});
}
}
String _capitalizeFirstLetter(String text) {
if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1);
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
children: [
if (widget.children != null && widget.children!.isNotEmpty)
GestureDetector(
onTap: () {
setState(() {
_isExpanded = !_isExpanded;
widget.onExpansionChanged?.call(_isExpanded);
});
},
child: Icon(
_isExpanded
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_right,
color: ColorsManager.lightGrayColor,
size: 16,
),
),
Expanded(
child: GestureDetector(
onTap: () {
if (widget.onItemSelected != null) {
widget.onItemSelected!.call();
}
},
child: Text(
_capitalizeFirstLetter(widget.title),
style: TextStyle(
color: widget.isSelected
? ColorsManager.blackColor
: ColorsManager.lightGrayColor,
fontWeight:
widget.isSelected ? FontWeight.w600 : FontWeight.w400,
),
),
),
),
],
),
if (_isExpanded && widget.children != null && widget.children!.isNotEmpty)
Padding(
padding: const EdgeInsets.only(left: 24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: widget.children!,
),
),
],
);
}
}