Skip to content

Instantly share code, notes, and snippets.

@urusaich
Created November 21, 2024 16:03
Show Gist options
  • Save urusaich/04aa785642276c57fb337a99ecf0b967 to your computer and use it in GitHub Desktop.
Save urusaich/04aa785642276c57fb337a99ecf0b967 to your computer and use it in GitHub Desktop.
class MyAnimatedCrossFade extends StatelessWidget {
const MyAnimatedCrossFade({
super.key,
required this.duration,
required this.index,
required this.children,
}) : assert(index >= 0 && index < children.length);
final Duration duration;
final int index;
final List<Widget> children;
@override
Widget build(BuildContext context) {
return Stack(
fit: StackFit.expand,
children: [
for (var i = 0; i < children.length; ++i)
AnimatedOpacity(
duration: duration,
opacity: i == index ? 1.0 : 0.0,
child: children[i],
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment