Reputation: 163
On Flutter, is there something similar to AnimatedSize
for slivers? I want to animate a sliver's size change.
What I Tried
When I just wrap a sliver with AnimatedSize
, Flutter throws these errors:
A RenderAnimatedSize expected a child of type RenderBox but received a child of type RenderSliverToBoxAdapter.
_AnimatedSizeState is a SingleTickerProviderStateMixin but multiple tickers were created.
Used this code:
class Testingyeye extends StatefulWidget {
const Testingyeye({Key? key}) : super(key: key);
@override
State<Testingyeye> createState() => _TestingyeyeState();
}
class _TestingyeyeState extends State<Testingyeye> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Testing"),
),
body: CustomScrollView(slivers: [
SliverToBoxAdapter(
child: AnimatedSize(
duration: Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn,
child: SliverList(delegate: SliverChildBuilderDelegate(
(context, index) {
return Text("hiii");
},
)),
),
)
]),
);
}
}
Ps I could find SliverAnimatedOpacity
, which animates the opacity of a sliver. I couldn't find the one for animating the size of the sliver tho.
Upvotes: 2
Views: 1009
Reputation: 63799
You can't use SliverList
inside non-sliver widget like AnimatedSize
here, instead use Column.
SliverToBoxAdapter(
child: AnimatedSize(
duration: Duration(milliseconds: 500),
curve: Curves.fastOutSlowIn,
child:Column(
children: List.generate(4, (index) => Text("A")),
) ,
),
)
You can wrap AnimatedSize
with SliverToBoxAdapter
.
SliverToBoxAdapter(
child: AnimatedSize(
duration: Duration(seconds: 1),
child:
),
)
Upvotes: 1