Instantly share code, notes, and snippets.

Embed
What would you like to do?
class _TicketsPageState extends State<TicketsPage>
with TickerProviderStateMixin {
AnimationController cardEntranceAnimationController;
List<Animation> ticketAnimations;
Animation fabAnimation;
@override
void initState() {
super.initState();
cardEntranceAnimationController = new AnimationController(
vsync: this,
duration: Duration(milliseconds: 1100),
);
ticketAnimations = stops.map((stop) {
int index = stops.indexOf(stop);
double start = index * 0.1;
double duration = 0.6;
double end = duration + start;
return new Tween<double>(begin: 800.0, end: 0.0).animate(
new CurvedAnimation(
parent: cardEntranceAnimationController,
curve: new Interval(start, end, curve: Curves.decelerate)));
}).toList();
fabAnimation = new CurvedAnimation(
parent: cardEntranceAnimationController,
curve: Interval(0.7, 1.0, curve: Curves.decelerate));
cardEntranceAnimationController.forward();
}
Iterable<Widget> _buildTickets() {
return stops.map((stop) {
int index = stops.indexOf(stop);
return AnimatedBuilder(
animation: cardEntranceAnimationController,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
child: TicketCard(stop: stop),
),
builder: (context, child) => new Transform.translate(
offset: Offset(0.0, ticketAnimations[index].value),
child: child,
),
);
});
}
_buildFab() {
return ScaleTransition(
scale: fabAnimation,
child: FloatingActionButton(
onPressed: () => Navigator.of(context).pop(),
child: new Icon(Icons.fingerprint),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment