import 'package:flutter/material.dart'; class Expand extends StatefulWidget { final Widget child; final bool expand; const Expand({super.key, this.expand = true, required this.child}); @override State createState() => _ExpandState(); } class _ExpandState extends State with SingleTickerProviderStateMixin { late AnimationController expandController; late Animation animation; @override void initState() { super.initState(); prepareAnimations(); _runExpandCheck(); } ///Setting up the animation void prepareAnimations() { expandController = AnimationController( vsync: this, duration: const Duration(milliseconds: 500)); animation = CurvedAnimation( parent: expandController, curve: Curves.fastOutSlowIn, ); } void _runExpandCheck() { if (widget.expand) { expandController.forward(); } else { expandController.reverse(); } } @override void didUpdateWidget(Expand oldWidget) { super.didUpdateWidget(oldWidget); _runExpandCheck(); } @override void dispose() { expandController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return SizeTransition( axisAlignment: 1.0, sizeFactor: animation, child: widget.child); } }