The-Agency/lib/ui/widgets/sidebar/project_section.dart

98 lines
2.2 KiB
Dart

import "package:shadcn_flutter/shadcn_flutter.dart";
import 'project_button.dart';
class ProjectSection extends StatefulWidget {
final String projectLabel;
final List<Widget> children;
final VoidCallback? onHeaderPressed;
ProjectSection({
required this.projectLabel,
this.children = const [],
this.onHeaderPressed,
});
@override
State<ProjectSection> createState() => ProjectSectionState();
}
class ProjectSectionState extends State<ProjectSection> with TickerProviderStateMixin {
bool _isCollapsed = true;
late AnimationController _sizeController;
late AnimationController _fadeController;
@override
void initState() {
super.initState();
_sizeController = AnimationController(
duration: Duration(milliseconds: 150),
vsync: this,
);
_fadeController = AnimationController(
duration: Duration(milliseconds: 250),
vsync: this,
);
if (!_isCollapsed) {
_sizeController.forward();
_fadeController.forward();
}
}
@override
void dispose() {
_sizeController.dispose();
_fadeController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ProjectButton(
label: widget.projectLabel,
collapsed: _isCollapsed,
onPressed: () {
setState(() {
_isCollapsed = !_isCollapsed;
if (_isCollapsed) {
_fadeController.reverse();
_sizeController.reverse();
} else {
_fadeController.forward();
_sizeController.forward();
}
});
widget.onHeaderPressed?.call();
},
),
Gap(2),
ClipRect(
child: Align(
alignment: Alignment.topCenter,
child: FadeTransition(
opacity: _fadeController,
child: SizeTransition(
sizeFactor: _sizeController,
child: Column(
spacing: 2,
children: [
...widget.children
],
),
),
),
),
)
],
);
}
}