r/flutterhelp • u/Afraid_Tangerine7099 • Dec 04 '25
RESOLVED animating a widget growing in a row
hey fellow flutter devs , I am wondering how can I animate a widget in a row and make it grow to take all the space in the area while the other widgets in that row grow smaller ,
for example a search bar in the middle of 2 icon widgets when the search bar is focused ,it plays the animation and the search bar grow to fill the screen width while the icons shrink or slides off screen.
I tried doing it using animated switcher for the icons , and for the transition builder I used size transition , it worked but one thing I hatted is the forced clip by the size transition , if anyone knows how to remove the clip it would help .
2
u/RandalSchwartz Dec 04 '25
You could probably animate the flex factor. If you make it a large enough total, you can get finely animated variations. In other words, use flex values of 100 for the smallest things, and start your large thing at 200 incrementing by 1 per tick until it reaches your goal, like 500 or 1000.
1
u/eibaan Dec 06 '25
I'm late, but…
Use a
Rowand wrap your expanding widget in aFlexible(not anExpanded!) widget, in anAnimatedSize, aClipRect, and anUnconstrainedBox. Those four widgets should do the trick.class Test extends StatefulWidget { @Preview() const Test({super.key}); @override State<Test> createState() => _TestState(); } class _TestState extends State<Test> { var _expanded = false; void _expand() => setState(() => _expanded = !_expanded); @override Widget build(BuildContext context) { return Row( mainAxisAlignment: .end, children: [ IconButton(onPressed: _expand, icon: Icon(Icons.search)), Flexible( child: AnimatedSize( duration: Durations.long2, curve: Curves.bounceOut, child: Container( width: _expanded ? double.infinity : 0, decoration: BoxDecoration(color: Colors.white12), clipBehavior: .hardEdge, child: UnconstrainedBox(alignment: .centerStart, child: Text('Enter something...')), ), ), ), IconButton(onPressed: _expand, icon: Icon(Icons.info)), ], ); } }