build method

  1. @override
Widget build({
  1. required Animation<double> animation,
  2. required Widget child,
  3. Map<String, Object?> params = const {},
})
override

Builds the animated widget for the forward direction.

animation0.0 → 1.0 where 0.0 = invisible/start, 1.0 = visible/end. child — the widget being animated. params — optional configuration map (typed by each plugin).

Concrete subclasses must override this method.

Implementation

@override
Widget build({
  required Animation<double> animation,
  required Widget child,
  Map<String, Object?> params = const {},
}) {
  final axis = (params['axis'] as FlipAxis?) ?? FlipAxis.y;
  final perspective = (params['perspective'] as double?) ?? 0.001;
  final halfTurns = (params['halfTurns'] as bool?) ?? true;
  final maxAngle = halfTurns ? math.pi : math.pi * 2;

  return AnimatedBuilder(
    animation: animation,
    builder: (_, c) {
      final angle = animation.value * maxAngle;
      final matrix = Matrix4.identity()
        ..setEntry(3, 2, perspective);

      if (axis == FlipAxis.x) {
        matrix.rotateX(angle);
      } else {
        matrix.rotateY(angle);
      }

      // Hide back face during second half of flip
      final showFront = angle <= math.pi / 2 || angle >= 3 * math.pi / 2;
      return Transform(
        transform: matrix,
        alignment: Alignment.center,
        child: showFront
            ? c
            : Transform(
                transform: axis == FlipAxis.y
                    ? (Matrix4.identity()..rotateY(math.pi))
                    : (Matrix4.identity()..rotateX(math.pi)),
                alignment: Alignment.center,
                child: c,
              ),
      );
    },
    child: child,
  );
}