Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Last active September 11, 2020 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodydavis/e83c58834892916915358c1fc18dd9a4 to your computer and use it in GitHub Desktop.
Save rodydavis/e83c58834892916915358c1fc18dd9a4 to your computer and use it in GitHub Desktop.
Flutter Animated IndexedStack
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