flipShuttleBuilder function

Widget flipShuttleBuilder(
  1. BuildContext flightContext,
  2. Animation<double> animation,
  3. HeroFlightDirection flightDirection,
  4. BuildContext fromHeroContext,
  5. BuildContext toHeroContext,
)

Implementation

Widget flipShuttleBuilder(
  BuildContext flightContext,
  Animation<double> animation,
  HeroFlightDirection flightDirection,
  BuildContext fromHeroContext,
  BuildContext toHeroContext,
) {
  return AnimatedBuilder(
    animation: animation,
    builder: (context, child) {
      // Rotation from 0 to Pi (180 degrees)
      final rotation = animation.value * math.pi;
      final isUnder = animation.value > 0.5;

      return Transform(
        transform: Matrix4.identity()
          ..setEntry(3, 2, 0.001) // Perspective
          ..rotateY(rotation),
        alignment: Alignment.center,
        child: isUnder
            ? Transform(
                transform: Matrix4.rotationY(math.pi),
                alignment: Alignment.center,
                child: toHeroContext.widget,
              )
            : fromHeroContext.widget,
      );
    },
  );
}