Instantly share code, notes, and snippets.

Embed
What would you like to do?
class _PriceTabState extends State<PriceTab> with TickerProviderStateMixin {
final List<GlobalKey<FlightStopCardState>> _stopKeys = []; //<--- Add keys
AnimationController _fabAnimationController;
Animation _fabAnimation;
@override
void initState() {
[...]
_initFabAnimationController(); //<--- init fab controller
_flightStops.forEach(
(stop) => _stopKeys.add(new GlobalKey<FlightStopCardState>())); //<-- init card keys
_planeSizeAnimationController.forward();
}
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
child: Stack(
alignment: Alignment.center,
children: <Widget>[_buildPlane()]
..addAll(_flightStops.map(_buildStopCard))
..addAll(_flightStops.map(_mapFlightStopToDot))
..add(_buildFab()), //<--- Add a fab
),
);
}
Widget _buildStopCard(FlightStop stop) {
[...]
child: FlightStopCard(
key: _stopKeys[index], //<--- Add a key
flightStop: stop,
isLeft: isLeft,
),
[...]
}
Widget _buildFab() {
return Positioned(
bottom: 16.0,
child: ScaleTransition(
scale: _fabAnimation,
child: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.check, size: 36.0),
),
),
);
}
void _initDotAnimationController() {
_dotsAnimationController = new AnimationController(
vsync: this, duration: Duration(milliseconds: 500))
..addStatusListener((status) { //<--- Add a listener to start card animations
if (status == AnimationStatus.completed) {
_animateFlightStopCards().then((_) => _animateFab());
}
});
}
Future _animateFlightStopCards() async {
return Future.forEach(_stopKeys, (GlobalKey<FlightStopCardState> stopKey) {
return new Future.delayed(Duration(milliseconds: 250), () {
stopKey.currentState.runAnimation();
});
});
}
void _initFabAnimationController() {
_fabAnimationController = new AnimationController(
vsync: this, duration: Duration(milliseconds: 300));
_fabAnimation = new CurvedAnimation(
parent: _fabAnimationController, curve: Curves.easeOut);
}
_animateFab() {
_fabAnimationController.forward();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment