Last active
September 11, 2020 19:12
-
-
Save rodydavis/e83c58834892916915358c1fc18dd9a4 to your computer and use it in GitHub Desktop.
Flutter Animated IndexedStack
This file contains 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
import 'package:flutter/material.dart'; | |
class AnimatedIndexedStack extends StatelessWidget { | |
const AnimatedIndexedStack({ | |
Key key, | |
@required this.index, | |
@required this.children, | |
@required this.duration, | |
}) : super(key: key); | |
final int index; | |
final List<Widget> children; | |
final Duration duration; | |
@override | |
Widget build(BuildContext context) { | |
return IndexedStack( | |
index: index, | |
children: [ | |
for (var i = 0; i < children.length; i++) | |
AnimatedOpacity( | |
opacity: index == i ? 1.0 : 0.0, | |
duration: duration, | |
child: children[i], | |
), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment