playAllVillains static method

Future playAllVillains(
  1. BuildContext context, {
  2. bool entrance = true,
  3. bool didPop = false,
})

Implementation

static Future playAllVillains(BuildContext context,
    {bool entrance = true, bool didPop = false}) {
  List<_VillainState> villains = VillainController._allVillainsFor(context)
    ..removeWhere((villain) {
      if (entrance) {
        if (!villain.widget.animateEntrance) return true;
      } else {
        if (!villain.widget.animateExit) return true;
      }
      if (didPop) {
        if (!villain.widget.animateReEntrance) return true;
      }
      return false;
    });

  // Controller for the new page animation because it can be longer then the actual page transition

  AnimationController controller = new AnimationController(
      vsync: TransitionTickerProvider(TickerMode.of(context)));

  SequenceAnimationBuilder builder = new SequenceAnimationBuilder();

  for (_VillainState villain in villains) {
    builder.addAnimatable(
      animatable: Tween<double>(begin: 0.0, end: 1.0),
      from: villain.widget.villainAnimation.from,
      to: villain.widget.villainAnimation.to,
      tag: villain.hashCode,
    );
  }

  SequenceAnimation sequenceAnimation = builder.animate(controller);

  for (_VillainState villain in villains) {
    villain.startAnimation(sequenceAnimation[villain.hashCode] as Animation<double?>);
  }

  //Start the animation
  return controller.forward().then((_) {
    controller.dispose();
  });
}