buildTransition method

  1. @override
Widget buildTransition(
  1. BuildContext context,
  2. Animation<double> animation,
  3. Widget child
)
override

Wrap child (the output of buildPresenter) in a transition driven by animation (0→1 on push, 1→0 on pop).

Override to customise. The default is a platform slide.

Implementation

@override
Widget buildTransition(
  BuildContext context,
  Animation<double> animation,
  Widget child,
) {
  final source = _cellRect;
  if (source == null) {
    return ScreenTransitions.responsive(context, animation, child);
  }
  final flight = _flightAnimation ??= CurvedAnimation(
    parent: animation,
    curve: Curves.easeOutCubic,
    reverseCurve: Curves.easeOutCubic.flipped,
  );
  final t = flight.value;
  return ListenableBuilder(
    listenable: this,
    builder: (context, _) {
      if (error != null) return Opacity(opacity: t, child: child);
      // Navigator measures an incoming route offstage before its first visible frame.
      if (ModalRoute.of(context)?.offstage != true) cellSource!.cover();
      return CameraFlight(
        source: cellSource?.rect ?? source,
        target: _previewSlot,
        progress: t,
        onDetach: cellSource!.uncover,
        background: _buildFrame(
          context,
          const SizedBox.expand(),
          background: true,
        ),
        chrome: child,
        preview: IgnorePointer(
          child: ClipRRect(
            borderRadius: BorderRadius.circular(8 * (1 - t)),
            child: CameraThumb(
              controller: controller,
              child: Stack(
                children: [
                  Opacity(
                    opacity: t,
                    child: CustomPaint(
                      painter: CameraGuidelinePainter(),
                      child: const SizedBox.expand(),
                    ),
                  ),
                  Opacity(opacity: 1 - t, child: const CameraCellIcon()),
                ],
              ),
            ),
          ),
        ),
      );
    },
  );
}