Created
November 21, 2024 16:03
-
-
Save urusaich/04aa785642276c57fb337a99ecf0b967 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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